Herz3h
Herz3h

Reputation: 712

List all files recursively in microsoft graph

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 ?

Upvotes: 6

Views: 6949

Answers (3)

TheKikkoman
TheKikkoman

Reputation: 1

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

Upvotes: 0

flyte
flyte

Reputation: 1322

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.

Upvotes: 4

Herz3h
Herz3h

Reputation: 712

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)

Upvotes: 3

Related Questions