Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a document library in a sharepoint online site using MS graph

I am able to access the documents on my one drive with requests like this one:

https://graph.microsoft.com/v1.0/me/drive/root/children

I am able to access a document library of a root sharepoint site of my company with a request like this:

https://graph.microsoft.com/v1.0/drive/root/children

It gives me the contents of the "root" library:

https://<my company>.sharepoint.com/Shared%20Documents

I am not able to access the document library of a SP subsite I created. e.g. this one:

https://<my company>.sharepoint.com/samplesp/Shared%20Documents

How can I access such a document library with MS Graph?

like image 935
Michael Avatar asked Oct 16 '25 03:10

Michael


1 Answers

For accessing SharePoint sites and lists check out documentation of the SharePoint API in Microsoft Graph.

Update:

For those who have problems with accessing default Drive (formerly "Documents" library) on a specific SharePoint site using MS Graph API:

You should look into the documentation for accessing files on OneDrive.

As said in the question, this endpoint gives us a list of files on private OneDrive:

.../me/drive/root/children

Drive on SharePoint's sites works in the same way, but instead of me you should provide global Id of the site you want to access (global Id is <hostName>,<siteCollectionId>,<siteId>).

In conclusion: this endpoint gives us a list of files on a specified site's default drive:

.../Sharepoint/sites/<hostName>,<siteCollectionId>,<siteId>/drive/root/children

If you want to access files on a specific list, all you need is the id of the list:

.../Sharepoint/sites/<hostName>,<siteCollectionId>,<siteId>/lists/<listId>/drive/root/children

Now it should be obvious.

like image 196
FIL Avatar answered Oct 19 '25 02:10

FIL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!