5

I'm trying to read the items from a list via REST within a SharePoint-hosted app, but in response I get 403 - Forbidden so I wonder which permissions do i need, I thought that web - read in the appManifest would be enough but it seems like it doesn´t, or maybe i missing something else, the endpoint i'm using is http://site url/_api/web/lists/GetByTitle(‘Test')/items, by the way I'm using angular 2 http module for this, like so:

 private url= "https://URL/_api/web/lists/GetByTitle('test')/items";  // URL to web API
          getItems(): Observable<any[]> {
            let headers = new Headers();
            headers.append('accept', 'application/json;odata=verbose');

            return this.http.get(this.url, {headers: headers})
                            .map(this.extractData)
                            .catch(this.handleError);
          }

         private extractData(res: Response) {
           let body = res.json();
           console.log(body);
           return body || { };
        }

So if somebody knows what's happening and how can I get the data it will be great

Thanks in advance

1
0

In order to access host data from a SharePoint-hosted add-in, you must use the AppContextSite endpoint, or the cross-domain library, RequestExecutor. The former can be done by changing your url to the following:

appUrl + "/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('test')/items?@target='" + encodeURIComponent(hostUrl) + "'"

More details, including how to use the cross-domain library, can be found here.

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.