GetFolderByServerRelativeUrl Rest API return Server relative urls must start with SPWeb.ServerRelativeUrl

g h 716 Reputation points
2020-12-18T07:15:44.747+00:00

I am trying to fetch all files from a folder in SharePoint. I am looking for all file stored under "Shared%20Ducuments" path:

https://{server_name}/sites/{sub_site}/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')/Files

Return this error:

<m:code>-2147024809, System.ArgumentException</m:code>
    <m:message xml:lang="en-US">Server relative urls must start with SPWeb.ServerRelativeUrl</m:message>

Can anyone help please ?

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,565 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jerryzy 10,561 Reputation points
    2020-12-21T02:18:58.283+00:00

    Hi @g h ,

    Please modify the Rest EndPoint like below:

    https://{server_name}/sites/{sub_site}/_api/web/GetFolderByServerRelativeUrl('/sites/sub_site/Shared%20Documents')/Files  
    

    The ServerRelativeUrl needs to prepend /sites/sitename.

    Thanks
    Best Regards


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    11 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful