0
votes

I am working on a script to upload files to a folder using Microsoft Graph API 1.0. I am trying to make it so the user running the script can copy and paste the path of a sharepoint/onedrive folder. I of course want to use the path as a destination for the files to be uploaded too. So far I cannot find a way to get this to work.

Path example: https://example.sharepoint.com/sites/TheSite/Shared%20Documents/User

API Reference: https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0

I have tried making GET calls to the API using the path, part of the path, and every variation of the hostname, and path. I am using the Python Requests library, and authentication is not an issue.

Errors received:

 "error": {
    "code": "itemNotFound",
    "message": "The resource could not be found."

and

  "error": {
    "code": "invalidRequest",
    "message": "Invalid hostname for this tenancy",
1
One more detail. All I really need is a unique identifier that the user get easily access. If there is some hidden place that folder IDs are visible in sharepoint/onedrive, then that would work too. I just cant seem to find them on the user facing side. File hosting sites like Box add the ID in the url, so its easy to get. That is what I would love to have.CamParker
Did you manage to resolve this??Ankit Kumar

1 Answers

6
votes

When we are using the storage path. we have to choose complete path for calling.whether it is Azure blob container or Sharepoint or Drive.

Please refer below link for uploading data

https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http https://medium.com/@rahul.metangale/upload-a-file-to-sharepoint-using-azure-graph-api-9deacce57449

steps to upload:

1)Generate Token - using tenant, client id, client secret

2)Get drive id GET https://graph.microsoft.com/v1.0/drives

3)Upload Document Smaller than 4MB: PUT https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/content Header: “Authorization” : “Bearer Body: binary (select binary option in body in postman) Upload a file using select file option file-name: is file name along with extension example: test.txt

4)Upload Document Greater than 4MB GET: https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/createUploadSession Header: “Authorization” : “Bearer This will return upload url Upload Document PUT Header: “Authorization” : “Bearer Body: binary (select binary option in body in postman) 4)Upload Document Greater than 4MB: Header: “Authorization” : “Bearer