1

I am trying to get the all the folders from SharePoint library using Graph API. But I am able to get only level one folder

  • Folder 1
    • Folder 1 Sub Folder
  • Folder 2
    • Folder Sub Folder

Using below code able to get Folder 1 and Folder 2 not sub folders names

https://graph.microsoft.com/v1.0/sites('a22d0d0a-68fb-40b3-9ef7-8001e691a')/lists('8af98cb6-bbf3-4599-b093-7287bcef')/drive/root/children

Is it possible using graph API to get the all the folders

1

You could try the below endpoint to get all folders in the SharePoint Document library:

https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$expand=fields&$filter=fields/ContentType eq 'Folder'

And you need to add request header Prefer: HonorNonIndexedQueriesWarningMayFailRandomly

enter image description here

2
  • It show below error messages "message": "Field 'ContentType' cannot be referenced in filter or orderby as it is not indexed. Provide the 'Prefer: HonorNonIndexedQueriesWarningMayFailRandomly' header to allow this, but be warned that such queries may fail on large lists.", "innerError": { Mar 16 '21 at 8:53
  • As I said, you need to add the request header Prefer: HonorNonIndexedQueriesWarningMayFailRandomly Mar 16 '21 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.