Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Getting error 401 in APIkey header with $http get and XMLHttpRequest but it's working with postman,Getting error 401 with $http get and XMLHttpRequest but it's working with postman

Not applicable

I have received a api from client and when I am trying to integrate it with angular service, getting 401 unauthorized error. But same is working with POSTMAN. Please suggest me if I am doing anything wrong.

Here is the code which I am trying:

$http({
       url:"https://xxx_test.com/data?sdate=date",
       method:"GET",
       headers:{'apikey':'key'},})

This is the response that I am getting :

{"fault":{"faultstring":"Failed to resolve API Key variable request.header.apikey","detail":{"errorcode":"steps.oauth.v2.FailedToResolveAPIKey"}}}

Console log:

angular.js:12265 OPTIONS apiurl?start_date=04/26/2018&end_date=04/26/2018 401 (Unauthorized) :3000/#/pos:1 Failed to load apiurl?start_date=04/26/2018&end_date=04/26/2018: Response for preflight has invalid HTTP status code 401.

,

favorite

I have received a api from client and when I am trying to integrate it with angular service, getting 401 unauthorized error. But same is working with POSTMAN. Please suggest me if I am doing anything wrong.

Here is the code which I am trying:

$http({
       url:"https://xxx_test.com/data?sdate=date",
       method:"GET",
       headers:{'apikey':'key'}})

This is the response that I am getting :

{"fault":{"faultstring":"Failed to resolve API Key variable request.header.apikey","detail":{"errorcode":"steps.oauth.v2.FailedToResolveAPIKey"}}}

Console log:

angular.js:12265 OPTIONS apiurl?start_date=04/26/2018&end_date=04/26/2018 401 (Unauthorized) :3000/#/pos:1 Failed to load apiurl?start_date=04/26/2018&end_date=04/26/2018: Response for preflight has invalid HTTP status code 401.

Solved Solved
0 12 7,914
1 ACCEPTED SOLUTION

Hi @sandeep pandey,

Even I had come across with the same issue recently ,can you just try enabling the CORS in Apigee.

Please follow the steps from the below link.

https://community.apigee.com/questions/22/apigee-pre-flight-options-requests.html

View solution in original post

12 REPLIES 12