Search code examples
angularjshttppostmates

Getting a 401 UNAUTHORIZED Error with Postmates API endpoint delivery_quotes


I have an angular application and I am making an http request with the testing key.

var authString = ('Basic '+ btoa("ef7d25e3-0771-46ba-b4f8-bc9ac719777a:"));

var url = 'https://api.postmates.com/v1/customers/cus_KHKFAOoa9PWhPF/delivery_quotes';
var headers = {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization':authString};

var req1 = { method: 'POST', 
          url: url, 
          headers:headers,
          data: params1, 
      };
return $http(req1);

The response is: 'No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access. The response had HTTP status code 401.'

I have this same code working in python with requests, but I am not sure why I can't get it working in my angular application.

I did set the default http headers:

$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];

I think the authentication is wrong somehow


Solution

  • We currently do not allow access control headers for security reasons. If you're doing API calls directly from the client, then you will most likely be exposing your API credentials.

    I recommend going the Python route, or check out this Node package from one of our community members: https://github.com/lambtron/postmates-node

    Let me know if you have any more questions!