I am using python with the sharepy module to make requests to sharepoint. I would really like to know to get get all of the folders, subfolders, and files of a sharepoint site via a http request. I can list folders and files like so:

r = s.get(spo_site + """_api/web/GetFolderByServerRelativeUrl('""" + root_folder + """')/Folders""")

But it need it to go deep into the folder structure to get the relative urls and names of the files and folders. I would think this would be possible considering most sites have an export to excel button. The reason I want to do this with code because I need to go through a bunch of sites. Please Help.

Mike Smith response answered my question. My code is like this:

r = s.get(spo_site + """_api/web/lists/getbytitle('Documents')/items?$select=FileLeafRef,FileRef&$top=5000)

This works great but the limit is 5000 items. I am going to need much more than this. Is there a solution for this?

1 Answer 1


A CAML query may work. If multiple calls are ok then:

You can get a list of libraries using:

_api/web/lists?$filter=BaseTemplate eq 101

Note that 101 is for the Document Library template. A long list of template IDs here: https://techtrainingnotes.blogspot.com/2015/02/sharepoint-2013-list-and-library.html

And then from the list of libraries, get every folder/file using:

  • Smith, Thank you mike this is working! One last question, how would you increase the number of items coming back? Right now I am only getting 100 back where I know have like 7,000 objects in my test directory. Thanks again! Aug 16, 2019 at 17:55
  • Add &$Top=5000. For more than your List Threshold Limit you will need to use paging. For library paging you can use Skip and Top: $Skip=10000&$Top=5000. Skip does not work for lists. Use $skiptoken and a little code. docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/… Aug 16, 2019 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.