Sharepoint 365 Rest Api cannot see any document or element
-
08-02-2021 - |
Frage
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:
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
Lösung
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
Andere Tipps
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