1

I have a SharePoint url which works perfectly fine this points to the production environment I am using nodejs with getFileByName method to consume this url -

https://xxxx.sharepoint.com/sites/MSDS/Construction/_api/web/GetFileByServerRelativeUrl('/sites/MSDS/Construction/ProductLabels/xxxx.pdf')/$value

Now below is the quality server url which doesn't work at all -

https://xxxx.sharepoint.com/sites/qa-MSDS/Construction/_api/web/GetFileByServerRelativeUrl('/sites/qa-MSDS/Construction/ProductLabels/xxxx.pdf')/$value

The difference is qa-MSDS instead of MSDS, when I use the qa web api I get below error -

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>-2147024809, System.ArgumentException</m:code>
<m:message xml:lang="en-US">
Server relative urls must start with SPWeb.ServerRelativeUrl
</m:message>
</m:error>

Can anyone suggest what I am doing wrong or how to solve this in a better way in node js environment?

Jeet
  • 5,569
  • 8
  • 43
  • 75
  • did you try encoding the url before using inside GetFileByServerRelativeUrl ? Possible duplicate of https://sharepoint.stackexchange.com/questions/214750/rest-api-error-server-relative-urls-must-start-with-spweb-serverrelativeurl – Vineet Desai Dec 09 '17 at 14:33
  • Yes I have tried that as well, with no help. – Jeet Dec 09 '17 at 15:45
  • Did you try GetFileByServerRelativeUrl('ProductLabels/xxxx.pdf') – Vineet Desai Dec 10 '17 at 03:05
  • Yup I tried all permutation and combinations of `site/folder/file.extension` – Jeet Dec 10 '17 at 13:14

0 Answers0