Jeff McKay
Jeff McKay

Reputation: 171

List child items of SharePoint document sub folder

I am trying to use Microsoft Graph to list and download files in SharePoint. I'm using direct http not any library. My problem is that I cannot list child items of subfolders found in SharePoint libraries.

I start the process by using this call to obtain a list of drive Ids:

https://graph.microsoft.com/v1.0/sites/host.sharepoint.com/drives

("host" is actually different for my site)

Let's say a driveId is "ABCDEF". I then use this call to obtain a list of files within the SharePoint drive:

https://graph.microsoft.com/v1.0/sites/host.sharepoint.com/drives/ABCDEF/root/children

This yields for each file a fileId and filename. If my document library has a subfolder created, I can differentiate between files and folders by looking for the item "folder". The id of the subfolder looks similar to those of files. Let's say the folder Id is "XYZ".

Now I want to obtain a list of child items for the sub folder. I use this call:

https://graph.microsoft.com/v1.0/sites/host.sharepoint.com/drive/items/XYZ/children

Unfortunately this results in http error 404 with the message "The resource could not be found". I have tried variations of this url, such as drives/XYZ/root/children but nothing works.

Could someone provide me with the correct url to obtain a list of files from within a SharePoint library subfolder?

Upvotes: 0

Views: 843

Answers (1)

Allen Wu
Allen Wu

Reputation: 16438

This is because the default drive host.sharepoint.com/drive/ is different from host.sharepoint.com/drives/ABCDEF.

XYZ is under ABCDEF rather than the default drive.

Use https://graph.microsoft.com/v1.0/sites/host.sharepoint.com/drives/ABCDEF/items/XYZ/children should resolve this issue.

Upvotes: 1

Related Questions