I've been setting up an app to query a Sharepoint Document list for files (amongst other things). Querying {{mainLink}}sites/{{subsite}}/_api/web/lists/Documents/Files on postman with the following headers works perfectly - so long as no files are present. postman headerss

The moment I upload and check in a file to one of the folders on this sharepoint directory, I immediately get error 500, "code": "-1, Microsoft.SharePoint.Client.UnknownError"

The moment I delete said file, I can again query the list and get back the folder metadata just fine.

When I test the same code against our internal sharepoint site (the errors are coming from integrating with a client of ours) it works without a single hitch, and now I'm just confused. my guess is that there is some setting on their system or some optional parameter on my postman that needs to be set to make file requesting work properly. My question is does anyone know why the 500 errors are conditionally happening and/or how to fix them?

I also get the same error going through the folder Web/Lists(guid'1234')/files('1234')/Children

I've now discovered that I don't get the errors when going through the relative folder url {{mainLink}}sites/{{subsite}}/_api/Web/GetFolderByServerRelativeUrl('Documents/In')/Files is working fine for some reason. I can work with the one functioning endpoint, but I'd still like to know why all the other perfectly valid requests fail the moment any files are uploaded to the sharepoint site

Update: I've now cross posted to stackoverflow https://stackoverflow.com/questions/70091369/sharepoint-rest-api-get-files-from-a-list-is-throwing-unknown-500-errors-only-w

1 Answer 1


That's how we retrieve files and folders in sharepoint with rest. Retrieve all of the files in a folder:

/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files

Retrieve a file with URL:

/_api/web/GetFileByServerRelativeUrl('/Folder Name/{file_name})

For folders and files with Sharepoint REST API, please refer to this documentation: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest

The endpoint you mentioned is used to get list items in a list, it would not work for files.

  • Thanks for the answer, I'm glad to know which endpoint is recommended in the documentation, but _api/web/lists/{ListName}/Files (and the rest of the endpoints mentioned) definitely do work some of the time - I've tested I can get back items of type MS.FileServices.File using all the endpoints in my post on our internal SP site. I'll definitely change my code to stick to the recommended and evidently more supported endpoint though, thanks for the advice :)
    – The Lemon
    Nov 28, 2021 at 23:24

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.