1

Say my filepath is http://server/subsite/library/folder/file.png. If I need to get information about a file, I need to do the following:

http://server/subsite/_api/web/GetFileByServerRelativeUrl('/subsite/library/folder/file.png').

Now the problem is I don't know which sections are the subsite(s), so I have to run the follow _vti_bin/webs.asmx/WebUrlFromPageUrl which will get me the web url. So for the above filepath it will return http://server/subsite and now I have the required context for the REST _api.

Is there an easier way of doing this? I'm relying on the REST api and the I know the asmx handlers are very old and deprecated. I don't mind doing two requests to get the information I want but is there a REST equivalent of _vti_bin/webs.asmx/WebUrlFromPageUrl?

Edit: I am calling the sharepoint rest api from an external service. It is not a sharepoint app.

2
  • For me (NGINX), given an any URL, it's not easy to get its webServerRelativeUrl/webAbsoluteUrl/siteAbsoluteUrl/siteServerRelativeUrl from _spPageContextInfo in JavaScript of a client browser or something, I also made a HTTP request (WebUrlFromPageUrl). If worrying about asmx handlers are very old and deprecated, maybe use new OData API (i.e. https://{{SPWebServer}}/_api/sp.web.getweburlfrompageurl(@v)?@v='xx') with X-RequestDigest header. See also sharepoint.stackexchange.com/questions/224893/… Commented Jun 15, 2021 at 7:41
  • The preceding {{SPWebServer}} may look like {{tenant}}.sharepoint.com or sharepoint.company0.com and it doesn't need siteServerRelativeUrl. And the API returns webAbsoluteUrl/siteAbsoluteUrl, e.g. {"value":"https://company0test2.sharepoint.com/tit"} for @v='https://company0test2.sharepoint.com/:x:/g/tit/EeFmOJxxxxxxxxxxxxxxxxxxxxxxx-eb0xxxxxxxxxxl1g?e=9kXxdl' Commented Jun 15, 2021 at 7:49

1 Answer 1

2

One option you may test is the one described here:

  1. Start with a URL to a given SharePoint item. For example: http://site/web/doclib/myDocument.docx
  2. Remove the name of the specific resource from the end of the URL, so that the URL points to a document library, folder, or list. IN this case: http://site/web/doclib/
  3. Append the REST service pointer and the /contextinfo operator to the URL: http://site/web/doclib/_api/contextinfo
  4. Read the form digest and webFullUrl properties from the response.
  5. Append the REST service pointer _api to the web URL
  6. Use the resulting URL and the form digest to make requests for other resources you need.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.