Reputation: 35
I have already tested this API and have made a GET request on the API using PostMan and got the response. But when trying to implement it on my Angular 6 application I get a 401 unauthorized error. This is my angular code.
this.http.get('https://api.channeladvisor.com/v1/orders',{headers:{'Authorization':'Bearer *token*','Content-Type':'application/x-www-form-urlencoded','cache-control':'no-cache'}})
.subscribe((response)=>{
this.channel=response;
console.log(this.channel)
})
}
I have the token and have not displayed it in the code for security reasons. I have a feeling it has something with the headers syntax but i'm not so sure.
Upvotes: 0
Views: 964
Reputation: 624
May you can try add them to your headers:
'authorization': 'bearer ' + token,
'Authenticationtoken': 'bearer ' + token,
'X-Requested-With' : 'XMLHttpRequest'
My API used CakePHP3, same issue happen long ago, after added above 3 parameters everything ok :)
And more, please track your request by developer tools, and compare the difference between sucess and failed.
Upvotes: 1