How to retrieve file IDs from nested SharePoint folders (3 levels deep) via Microsoft Graph API

Describe the problem/error/question
I am using the HTTP Request node to interact with the Microsoft Graph API for SharePoint. My goal is to get a specific file ID so I can download the data.

The target data is located three folders deep inside SharePoint. Currently, I only know how to retrieve data from the first folder level. I need help modifying my endpoint URL to reach the nested folder (e.g., Folder1/Folder2/Folder3).

Status Quo: I can successfully get one folder deep using this URL:
https://graph.microsoft.com/v1.0/sites/{{ $json.ID }}/drive/root:/FOLDER_NAME/children?$select=id,name&$top=999

1 Like

Hi @Benry_Hendix
i think you can just extend the path in the root section of your url, umm somewhat like this:
https://graph.microsoft.com/v1.0/sites/{{ $json.ID }}/drive/root:/Folder1/Folder2/Folder3:/children?$select=id,name&$top=999
and ya i have did this part a little wrong so consider reading this also when dealing with folder names:

2 Likes

Hi @Anshul_Namdev ,

Thanks a lot, that worked!

I have one follow-up question. My folder structure looks like this: StaticName / DynamicName / StaticName. The folders on the first and third levels always have the exact same static name, but the second-level folder changes dynamically. Is there a way to structure the Microsoft Graph API HTTP request to search directly for that third-level folder without knowing the specific name of the second-level folder?

@Benry_Hendix Ummmmmm… for that i guess you need an extra step, like:

1st → list all second level folders to discover the dynamic name:
something like this ig:
https://graph.microsoft.com/v1.0/sites/{{ $json.ID }}/drive/root:/StaticName:/children?$select=id,name&$filter=folder ne null

2nd → Now use the discovered name to navigate to the third level folder:
https://graph.microsoft.com/v1.0/sites/{{ $json.ID }}/drive/root:/StaticName/{{ $json.name }}/StaticName:/children?$select=id,name&$top=999

I mean that is how i think the dynamic and all other would work, although this can be a little error prone related to strings and folder names but this should work mostly if the folder names are not too crazy.

Glad that helped you consider marking that as a solution so that people know how to tackle your situation in future. :smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.