0

I'm using Sharepoint online (included in office 365) I'd like to use sharepoint as a document repository.

I've created some test folders&Docs on my created test site: enter image description here

I have created my auth token with this: https://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/

With the Rest API V1 and postman When I list the root folders as described here I have this kind of error:

Server relative urls must start with SPWeb.ServerRelativeUrl

So as if I remove the first "/" like this

/_api/web/GetFolderByServerRelativeUrl('Documents')/Folders

I get a 200 response with an empty array 😕

I did browse aproximatly every endpoint of this HATEOS list but did not find any interesting data in return

/sites/Contentieux/_api/web/lists

Where my created documents could be hidden?

EDIT: See the full response in comments of answered post

2 Answers 2

1

It is "server" relative, not "site" relative. The server relative URL for your document library is /sites/Contentieux/Documents. So your API call would be:

https://<<your tenant>>.sharepoint.com/sites/Contentieux/_api/web/GetFolderByServerRelativeUrl('/sites/Contentieux/Documents')/Folders

3
  • Well even with this https://<<tenant>>.sharepoint.com/sites/Contentieux/_api/web/GetFolderByServerRelativeUrl('/sites/Contentieux/Documents')/Folders this gives "d": { "results": [] }
    – bodtx
    Commented Feb 14, 2020 at 11:00
  • When you browse to that library in your web browser, check the URL in your address bar. To confirm the path of your library. It is likely different than the displayed Title.
    – willman
    Commented Feb 14, 2020 at 11:20
  • wooooouu, thx you bring me to the right place with url displayed on the bottom of the screen once inside an document. the trick is that the URL is in french, thought everything would be in english: https://<<your tenant>>.sharepoint.com/sites/Contentieux/_api/web/GetFolderByServerRelativeUrl('/sites/Contentieux/Documents partages')/Files
    – bodtx
    Commented Feb 14, 2020 at 11:30
1

You need to pass the URL related to your site URL. Check below examples:

To get folders in document library:

http://site url/_api/web/GetFolderByServerRelativeUrl('/sites/SiteName/Shared Documents')/folders

To get files in document library/folder:

http://site url/_api/web/GetFolderByServerRelativeUrl('/sites/SiteName/LibraryURL/Folder Name')/Files

To get all Files and Folders in one call:

http://site url/_api/web/GetFolderByServerRelativeUrl('/sites/SiteName/Shared Documents')?$expand=Folders,Files

Reference: Get all Files and Folders in one call

3
  • Well even with this https://<<tenant>>.sharepoint.com/sites/Contentieux/_api/web/GetFolderByServerRelativeUrl('/sites/Contentieux/Documents')/Folders this gives "d": { "results": [] }, tried '/sites/Contentieux/Shared Documents' also, maybe a problem with my auth token, but it would not say http 200 status :\
    – bodtx
    Commented Feb 14, 2020 at 11:01
  • You need to pass the URL of document library and not the display name. that's why I added "Shared Documents" as this is the URL name of default document library (Documents) comes with SharePoint site. Can you please share the complete code with us? Commented Feb 14, 2020 at 11:04
  • ok thx for help, the root url contains french translatation of shared documents: https://<<your tenant>>.sharepoint.com/sites/Contentieux/_api/web/GetFolderByServerRelativeUrl('/sites/Contentieux/Documents partages')/Files
    – bodtx
    Commented Feb 14, 2020 at 11:31

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.