How to Add API-key and API-username in Angular services

can anyone please guide me How to Add API-key and API-username in Angular services
for example
return this.http.get(‘https://converge.trydiscourse.com/categories.json’, { ‘Api-Key’: ‘123456789’, ‘Api-Username’: ‘system’});
here i am getting error.

I suspect that the issue is happening because your code it adding the Api-Key and Api-Username as query parameters to the GET request. The Api-Key and Api-Username needed to be included in the request’s headers, not as query parameters. There is a curl example of how to set this up in the Authentication section that is near the top of this page: https://docs.discourse.org/.

Issue resolved by my self
fetchCategory() {
const headers = new HttpHeaders()
.set(‘Api-Key’, ‘123456’)
.set(‘Api-Username’, ‘abcd’);
const result = this.http.get(‘https://url.json’,{headers }); return result;
}
And also i enabled the cors from by browser and now its working fine

1 Like