2
votes

I am trying to make call to sharepoint LIST REST APIs. I am logged in to sharepoint and when in browser i type like

https://myserver.sharepoint.com/sites/mylist/_api/lists/getbytitle('OEC_Docs')/items

It returns me data in the browser as expected. However using the code like below in my angular 4 app throws 403

getDocs(){

  const httpOptions = {
      headers: new HttpHeaders({
          'Accept':  'application/json;odata=verbose',
          'Content-Type': 'application/json'
        })
      };

  return this.http.get(this.sharePointRestHost, httpOptions)
}

As the app is running on localhost in the same browser so i am expecting it to work. Please advise how to fix it.

1

1 Answers

0
votes

I am logged in to sharepoint

Yes, you are logged in and that's why you can see results in browser

But your angular app most likely isn't logged in. That's why it can't get the results and getting 403 (forbidden)

Try to:

  1. check the api docs, may be they are requiring something (cookies, headers, session) to authorize our app when it makes requests.

  2. compare session, cookies, local storage in both cases, I believe you will see a difference