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

New contributor
bodtx is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
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

  • Well even with this https://<<tenant>>.sharepoint.com/sites/Contentieux/_api/web/GetFolderByServerRelativeUrl('/sites/Contentieux/Documents')/Folders this gives "d": { "results": [] } – bodtx Feb 14 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 Feb 14 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 Feb 14 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

  • 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 Feb 14 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? – Ganesh Sanap Feb 14 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 Feb 14 at 11:31

Your Answer

bodtx is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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