Hi @Larry Bellou,
To list the folders and download files recursively from a SharePoint site using the Microsoft Graph API, you need to ensure that you have the correct permissions and are using the right API endpoints.
- Permissions: Ensure that your application has the necessary permissions to access the SharePoint site and its contents. The permissions you mentioned (
Sites.Selected
,Sites.Read.All
,Files.Read.All
,Sites.FullControl.All
) should generally allow you to read files and folders. However, you may need to verify that the permissions are granted for the specific site and that they are not just granted at the tenant level. - API Endpoint for Folders: To retrieve the folders within a specific directory, you can use the following endpoint:
Make sure to replaceGET https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/Resource%20Center:/children
{site-id}
with the actual site ID you obtained. TheResource Center
should be the correct path to the folder you want to access. - Access Denied Issue: If you are getting an "access denied" error, it could be due to insufficient permissions or because the folder path is incorrect. Double-check that the folder name is correctly encoded in the URL (e.g., spaces should be replaced with
%20
). - Recursive Download: To download files recursively, you will need to:
- List the folders using the endpoint mentioned above.
- For each folder, call the same endpoint to retrieve its children.
- If a child is a file, download it using:
GET https://graph.microsoft.com/v1.0/sites/{site-id}/drive/items/{item-id}/content
- If a child is a folder, repeat the process.
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.