How to get all the items contained inside a office365 onedrive
Asked Answered
M

3

4

I want to get all the files and folders contained inside a office365 onedrive folder in one rest API call, is there any option to do it?

Meuse answered 9/6, 2016 at 11:7 Comment(1)
Do you mean the children of a specific folder or children of the folder, and all descendents?Newfeld
B
0

There isn't a specific API call to retrieve a flat representation of a Drive. You can achieve a similar effect however using the drive's search method.

Simply pass an empty query string and it will return metadata for each file (regardless of it's directory):

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

Borrowing answered 10/6, 2016 at 19:57 Comment(4)
I was trying out the search, one of the things I observed is that it gives inconsistent results, the drive had plenty of items that were recently uploaded but they were not getting listed as part of the search even after couple of minutes. For another drive they were getting listed.Corcoran
when I do this it is just always empty! why might that be anyone know?Entomophagous
This does not work, as of 11-Jan-2020. It returns a status code 400 "invalid request" with the error message "Search Query cannot be empty."Eggshaped
This API almost does that, except it always misses some files, as if they were not indexed (even after waiting few days, they never get returned by the API, not sure why)Forcible
O
1

Another approach got from here is using Delta-Query:

https://graph.microsoft.com/v1.0/drives/[DRIVEID]/root/delta

This works also for specific Item-Ids:

https://graph.microsoft.com/v1.0/drives/[DRIVEID]/items/[ITEM ID]/delta
Overcrop answered 20/9, 2023 at 8:59 Comment(0)
B
0

There isn't a specific API call to retrieve a flat representation of a Drive. You can achieve a similar effect however using the drive's search method.

Simply pass an empty query string and it will return metadata for each file (regardless of it's directory):

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

Borrowing answered 10/6, 2016 at 19:57 Comment(4)
I was trying out the search, one of the things I observed is that it gives inconsistent results, the drive had plenty of items that were recently uploaded but they were not getting listed as part of the search even after couple of minutes. For another drive they were getting listed.Corcoran
when I do this it is just always empty! why might that be anyone know?Entomophagous
This does not work, as of 11-Jan-2020. It returns a status code 400 "invalid request" with the error message "Search Query cannot be empty."Eggshaped
This API almost does that, except it always misses some files, as if they were not indexed (even after waiting few days, they never get returned by the API, not sure why)Forcible
P
-1

Ok, try this search request:

https://graph.microsoft.com/v1.0/me/drive/root/search(q='%2A')

Or:

https://api.onedrive.com:443/v1.0/drives/(driveid)/items/(itemid)/view.search?q=%2A

Where %2A is asterisk, itemid may be a root folder id. Don't forget about pagination.

Or with OneDriveSDK:

_connection.SearchForItemsAsync(odFolder.ItemReference(), "*", ItemRetrievalOptions.Default)

Don't use "expand" query with search query. This should return all items in current folder recursively - sub-folders, sub-items.

Phyllous answered 7/8, 2020 at 4:52 Comment(2)
This solution doesn't work.Indiscriminate
@Indiscriminate probably this was changed by Microsoft. So, doesn't work anymorePhyllous

© 2022 - 2025 — McMap. All rights reserved.