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

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.

Your Answer

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.