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 ?

Herz3h
  • 614
  • 5
  • 20
  • 2
    Possible duplicate of [How to get all the items contained inside a office365 onedrive](https://stackoverflow.com/questions/37724252/how-to-get-all-the-items-contained-inside-a-office365-onedrive) – Marc LaFleur Feb 25 '19 at 20:37
  • 1
    Thanks for the link. – Herz3h Feb 25 '19 at 21:37
  • 1
    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....... – Herz3h Jul 01 '21 at 08:14

3 Answers3

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)

Herz3h
  • 614
  • 5
  • 20
1

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.

flyte
  • 1,242
  • 11
  • 18
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