SOLVED

SharePoint REST API: How to retrieve all folders in a list?

Copper Contributor

Hello All,

Does SharePoint allow to retrieve all folders in a List? (Not a Doc Library). Just a basic List.

I am using SharePoint Online.

I tried /_api/web/lists/GetById('${ListID}')/Folders without luck.

 

And please can someone share a link to a comprehensive SPO Lists & Doc Lib REST API reference?

I only have this https://msdn.microsoft.com/en-us/library/office/jj860569.aspx#Reference .

Is it not outdated?

5 Replies
best response confirmed by imbourg (Copper Contributor)
Solution

Hi @imbourg

 

You can filter by content type for example.

/_api/web/lists/GetByTitle('Documents')/items?$filter=ContentType eq 'Folder'

From here you can then select and expand other properties to return what you need.

 

Hope this helps

Thank you @Joel Rodrigues

 

I also found this: 

/_api/web/lists/GetById('${ListID}')/Items?$filter=FSObjType eq 1

But the problem is that just like yours, the response does not give the folders' names.

Then I found:

 

/_api/web/lists/GetById('${ListID}')/rootFolder/Folders

It gives the folders' name but curiously it finds an additional folder named Item :( 

Even with a list without folders, it will list that weird folder...

 

Thanks very much

@imbourg 

 

Using FSSobjType is another valid way of doing it.

Having to access the /Folders endpoint is what I meant with selecting and expanding the required properties. You have multiple properties you can select/expand to get all the information you need as they may be split across different endpoints.

 

Glad it's working for you :)

Sorry the delay in replying back. Swapped phone and had issues with MFA...

 

Joel 

Thank you Joel. I am working on SharePoint Online and used the api to get all folders from a Document Library. I have issue when i use $select=FileLeafRef,FileRef,Id. The return JSON object have duplicate ID property like (Id and ID) both have same value. This is a issue while parsing JSON in PowerAutomate as schema contains duplicate properties. Any help appreciated to avoid getting duplicate ID property.. Thank you

@Joel Rodrigues I have a feeling that no matter how complex site content types get, any instance of any type will always have a field "FSObjType" that is always equal to 0 for non-folders and 1 for folders. I myself am trying to filter out folders and Document Sets but include everything else. Is this the way to do this?

1 best response

Accepted Solutions
best response confirmed by imbourg (Copper Contributor)
Solution

Hi @imbourg

 

You can filter by content type for example.

/_api/web/lists/GetByTitle('Documents')/items?$filter=ContentType eq 'Folder'

From here you can then select and expand other properties to return what you need.

 

Hope this helps

View solution in original post