List all files recursively in microsoft graph
Asked Answered
S

3

5

We are trying to retrieve all files under a folder recursively, but I can't find an API for that.

I've tried using the search API without a query, but this doesn't return anything.

https://graph.microsoft.com/v1.0/sites/root/drive/root/search(q='{}')

Is this possible in microsoft graph ?

Shrinkage answered 25/2, 2019 at 10:33 Comment(3)
Possible duplicate of How to get all the items contained inside a office365 onedriveCarom
Thanks for the link.Shrinkage
Just as a note, the best way is to use delta api, store files metadata locally and query database using recursive query to get list of files.......Shrinkage
S
3

It turns out the correct link is:

https://graph.microsoft.com/v1.0/sites/root/drive/root/search(q='')

Thanks @Marc LaFleur

2021 edit: this api unfortunately doesn't return all the files. So I ended up using the sharepoint delta api to sync sharepoint data locally, then I use a mysql query to find all files of a given folder (there is a child <-> parent relation in the files/folder metadata return from the API)

Shrinkage answered 25/2, 2019 at 21:40 Comment(0)
C
3

If you want to find all of the files recursively of a SharePoint Document Library (which is still a Drive), you can apply a filter on the Content type not being a Folder. for example:

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

This will return all of the Documents (i.e.: anything not a folder) recursively. Since the driveItem is being expanded, you will have all of the DriveItem details needed.

Consistent answered 20/11, 2021 at 0:58 Comment(0)
W
0

I am able to list all items with this below :

{drive-root-id} is the /Drive/root "id" value return from :

https://graph.microsoft.com/v1.0/{site-id}/drive/root

Then :

https://graph.microsoft.com/v1.0/{site-id}/drive/items/{drive-root-id}/children
Wore answered 8/11, 2022 at 5:32 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.