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


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

1 Answer 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

  • 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, 2021 at 8:53
  • As I said, you need to add the request header Prefer: HonorNonIndexedQueriesWarningMayFailRandomly Mar 16, 2021 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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