An API that connects multiple Microsoft services, enabling data access and automation across platforms
Hello Amit Rawat,
Thanks for posting.
There's no endpoint to get all items in a drive with every file from every subfolder at once.
To get the item-ID of a file that is present in a multi-subfolder level using Graph API, you need to list children of a drive and traverse through the folder structure by using '/children' endpoint. This needs to be done recursively to reach the target folder (The item-ID needs to be replaced with lower-level folder (Item-ID)). The response will have id, name of items and other details. You can identify whether an item is a folder or a file by looking for "files" or "folder" property for that specific Item in response. Refer drive Items resource.
To list children in the root of the current user's drive: This will list all the items (folders and files) along with the Item-IDs present in drive at root level.
GET https://graph.microsoft.com/v1.0//me/drive/root/children
GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/root/children
To list children of a DriveItem with a known path: This returns the list of items in the children collection of the target item. Refer this.
GET /drives/{drive-id}/root:/{path-relative-to-root}:/children
Similar posts:
- https://learn.microsoft.com/en-us/answers/questions/1084332/how-do-i-navigate-into-subfolders-using-msgraphapi
- https://learn.microsoft.com/en-us/answers/questions/1190829/how-to-get-itemid-of-a-file-to-be-downloaded-from
Hope this helps.
If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.