0
votes

Here is the uber api documentation:

curl -H 'Authorization: Token <SERVER_TOKEN>' \
     -H 'Accept-Language: en_US' \
     -H 'Content-Type: application/json' \
     'https://api.uber.com/v1.2/estimates/price?start_latitude=37.7752315&start_longitude=-122.418075&end_latitude=37.7752415&end_longitude=-122.518075'

Here is the code I am using:

jQuery.ajax({
            type: "GET",
            url: "https://api.uber.com/v1.2/estimates/price?start_latitude=37.7752315&start_longitude=-122.418075&end_latitude=37.7752415&end_longitude=-122.518075",
            beforeSend: function(xhr) {

                xhr.setRequestHeader("Authorization", "Token <myToken>");
                xhr.setRequestHeader('Accept-Language', 'en_US'); 
                xhr.setRequestHeader('Content-Type', 'application/json');
                xhr.setRequestHeader("Access-Control-Allow-Origin","*");

            },
            success: function(data){
               console.log(data);
            }
        });

The error I am receiving is "Access to XMLHttpRequest at 'https://api.uber.com/v1.2/estimates/price?start_latitude=37.7752315&start_longitude=-122.418075&end_latitude=37.7752415&end_longitude=-122.518075' from origin 'null' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response."

I figured that would have been handled in my headers, but I have gone awry somewhere.

Thanks in advance!

EDIT: CORRECT RESPONSE BELOW

1
cors headers are response headers you can't control what uber does. - Daniel A. White

1 Answers

2
votes

According to Uber documentation, the API supports CORS for validating the origins that will invoke Uber API using your server token.

CORS validates the origin domain of the requests that reaches the API, as a mechanism to prevent not allowed sources from consuming your API. This is not an authentication scheme, however. You can read more information here CORS.

To fix this, you need to configure the origin domain from where you are doing the request into the configuration for your App in Uber, in the Security section from your App Settings: Cross-Origin Resource Sharing