Im currently testing the Uber API, and I havent been able to get any results yet, since my webapp is getting a "Access-Control-Allow-Origin" issue:
XMLHttpRequest cannot load https://api.uber.com/v1/estimates/price. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost' is therefore not allowed access. The response had HTTP status code 422.
I've set already the origin URI: https://localhost
But the Access-Control-Allow-Origin error keeps coming. I will try to recreate the app on the Uber side, but Its kind of odd that it doesn't work the way its intended.
You need to set
http://localhost:{PORT NUMBER}
as the allowed origin URI in the Authorizations tab of your developer dashboard. You'll want to update that URI to whichever you end up using in production.See the documentation for CORS: https://developer.uber.com/docs/rides/api-reference
Thanks for your msg 7imon7ays, it works also without the port.
It turns out that I got messed up with the LatLng Objects. The way I figured it out was, this: Since "https://api.uber.com/v1/estimates/price" is a GET I tested this url on a browser:
"https://api.uber.com/v1/estimates/price?start_latitude=37.625732&start_longitude=-122.377807&end_latitude=37.785114&end_longitude=-122.406677&server_token=xxxxxxx"
(replace xxxxxx with your server_token)...
And it worked!, I was able to see the output as expected, so digging deeper, I added a console.log(uberParams) <- to my uberParams, and it turns out that all of them but the key were undefined:
This is what I was using: (Wrong)
Where origin and destination are both google.maps.LatLng Objects. So, for the API, I was incorrectly sending this:
And the UBER Api, was returning THIS ERROR: -> Access-Control-Allow-Origin
That caused the confusion, because the origin_uri wasn't the problem, as soon as I changed the params to this:
Everything worked as expected. A Note to my Uber Friends: "Great API, poor Error handling and descriptions..."
On you dashboard, for example, if your redirection Url is http://localhost:8888/book/user/return
Then your origin Url should be http://localhost:8888 no slash at the end.