Get all the files and folders in the library of SharePoint Online site with one request

Kelly 81 Reputation points
2021-11-22T14:30:30.107+00:00

I am getting the files of a folder using this: https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-1.0&tabs=http. This works fine for me.

But the endpoint can only get the files in the first level, it cannot get the files in the subfolders. I need to loop through all the folders to get the files, this is not an option.

My library is like this: foler ->subfolder ->sub subfolder ->files. All the folders have files and subfolders. I just want to get all the files using one request. Is it possible?

Kelly

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,448 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,810 questions
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,026 Reputation points
    2021-11-23T05:39:55.84+00:00

    Hi @Kelly ,

    As a workaround, you could get all the list items in the library using this endpoint:

    https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$expand=driveItem  
    

    In the response, it would contaion all the files and folders in the specifice library.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

0 additional answers

Sort by: Most helpful