3

I need to query a list located inside a SharePoint hosted app, when located on host web, using JavaScript (REST preferably).
I control both app and host.

It's possible to communicate with an app part using window.addEventListener('message', m => ...), but I need to load the data from several SPWebs, and the app part can't be added to all pages.
SP.AppContextSite does not work, since host web does not have an app context.

3

You do not need to do anything special to access AppWeb resources from the HostWeb. The AppWeb is just a child site of the HostWeb so you can access it that way.

REST API accessing AppWeb

  • 1
    So simple I didn't even think about it. Thanks a bunch :D Note to reach the API I had to do this: /MyWeb/MyAppWeb/_api/Web/.... – eirikb Feb 19 '16 at 14:33
  • 1
    thank you for this comment! it's more descriptive then the answer itself :D – Serhiy Mar 6 '16 at 15:20
  • The answer also shows the URL - it's in the URL bar in the browser. I kinda thought that would be obvious. – Rob Windsor May 1 '16 at 21:54
  • @RobWindsor I think there is a slight difference, in your screenshot you call _api on the parent web, while I had to call _apion the app web (sub web). But yeah it's quite obvious – eirikb May 2 '16 at 6:55
  • I didn't see that originally. If that's what you did you misunderstood my answer. Code running in the host web can access data stored in app web from the host web's REST API endpoint. The app webs are just children of the host web so you can access them using <host web url>/_api/Web/Webs collection. – Rob Windsor May 2 '16 at 14:12

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.