0
votes

I want to be able to upload a text document to a SharePoint List. Since it is actually a Document Library, I believe I should upload files as though I am uploading to a Drive. I can upload a file to the site's root location. I can get the ID of the List I wish to upload to. However the Microsoft Graph API does not appear to like the ID I provide when I use that as the destination. ListItem says that ListItems are exposed as DriveItems when using a Document Library. How to upload a small file to SharePoint.

I have been testing with C# and GraphExplorer. It boils down to my endpoint being incorrect.

When using Graph Explorer, I can query for all drives with these two queries:

graph.microsoft.com/v1.0/sites/{siteid}/drives

The query displays the Drive Name I am looking for and the ID it shows is different than its list ID. This indicates to me that a Document Library has a separate List ID and Drive ID.

Status Code 201 (Created): graph.microsoft.com/v1.0/sites/{siteid}/drive/items/root:/testplaceholder.txt:/content

Status Code 404 (Not Found): graph.microsoft.com/v1.0/sites/{siteid}/drive/items/{listid}:/testplaceholder.txt:/content

Status Code 400 (Bad Request): graph.microsoft.com/v1.0/sites/{siteid}/drive/items/{driveid}:/testplaceholder.txt:/content

Can anyone tell me where my understanding is lacking, or where I might have messed up? Sorry for the lack of code formatting, couldn't get it to work on the URL strings.

ANSWER:

Using the Drive ID I found with the first query above.

graph.microsoft.com/v1.0/sites/{siteid}/drives/{driveid}/root:/testplaceholder.txt:/content

1

1 Answers

1
votes

Sample endpoint to upload file to a library.

https://graph.microsoft.com/v1.0/sites/siteid/drives/b!zEu8xWMaOU-BdU94l2XA7SAospdkDeREgpABeq2Ahp2VZN3js8mQTq_JU5kiCSsB/root:/test.txt:/content