Laura Schmitt
Laura Schmitt

Reputation: 1

Calling uber API

When I call ubers API from my front end, the call gets blocked with the following error: No 'Access-Control-Allow-Origin' header is present on the requested resource. However, when I call from a node js application the call goes through just fine. The code is the exact same. See below:

$.ajax({
url: "https://api.uber.com/v1/estimates/price",
headers: {
  Authorization: "Token " + uberServerToken
},
success: function(result) {
};

Upvotes: 0

Views: 156

Answers (1)

hugos
hugos

Reputation: 1323

This is due to CORS policy enforced by the browser. For cross domain requests the server must include a header Access-Control-Allow-Origin: *. This is likely on purpose as you should never include a server tonken in your client code. For the client you should be using a bearer token. Take a look at the Uber API documentation.

Since the server is at your own control you're free to make API requests to anywhere.

Upvotes: 2

Related Questions