I'm using the Uber API to create a ride request (with node-uber)
I first get the user authenticated (uber.authorization
after getting a calback from uber.getAuthorizeUrl
).
Then I call the estimate API and get a response (estimates.getPriceForRoute
)
I then use the same start & end coordinates with the product ID returned in the estimate (requests.create
).
I always get back: HTTP Response with error code: 409
Any suggestions?
UPDATE Here is the code for the estimate request (which works perfectly)
router.get('/estimate', function(request, response, next) {
var query = url.parse(request.url, true).query;
if (!query || !query.start_lat || !query.start_lng || !query.end_lat || !query.end_lng) {
response.sendStatus(400);
} else {
uber.estimates.getPriceForRoute(query.start_lat, query.start_lng, query.end_lat, query.end_lng , 1, function(err, res){
if (err) {
console.error(err);
response.sendStatus(500);
} else {
var productType = getProductType(query);
var selectedProduct = _.find(res.prices, function(price){
return price.display_name == productType;
});
response.json(selectedProduct);
}
});
} });
Here is the response I get
{"localized_display_name":"uberX","high_estimate":7,"minimum":7,"duration":240,"estimate":"$7-7","distance":0.95,"display_name":"uberX","product_id":"a1111c8c-c720-46c3-8534-2fcdd730040d","low_estimate":7,"surge_multiplier":1,"currency_code":"USD"}
Now the part that has the problem:
router.get('/request', function(request, response, next) {
var query = url.parse(request.url, true).query;
if (!query || !query.start_lat || !query.start_lng || !query.end_lat || !query.end_lng || !query.productId) {
response.sendStatus(400);
} else {
uber.requests.create({
"product_id": query.productId,
"start_latitude": query.start_lat,
"start_longitude": query.start_lng,
"end_latitude": query.end_lat,
"end_longitude": query.end_lng
}, function (err, res) {
if (err) {
console.error("error: " + err);
response.sendStatus(400);
} else {
//console.log(res);
response.json(res);
}
});
}
});
the line console.error("error: " + err);
returns this output:
error: HTTP Response with error code: 409