4ked
4ked

Reputation: 18

Bad Request error in uber api

I've been trying to get the uber price estimates endpoint working, but I'm stuck on an error that leads me to a blank page saying, "Bad Request." The console also says "callback not a function" but I can't seem to find out what is wrong.

My route:

//  Get an upfront fare before requesting a ride
app.get('/v1.2/estimates/price', function(request, response) {
    // extract the query from the request URL
    var query = request.query;

    // if no query params sent, respond with Bad Request
    if (!query || !query.lat || !query.lng) {
      response.sendStatus(400);
    } else { 
          uber.estimates.getPriceForRouteAsync( {
              "product_id": "33de8094-3dc4-4ca9-8f67-243275f57623", 
              "start_latitude": "38.9597897", 
              "start_longitude": "-94.60699369999999",
              "end_latitude": "39.010969", 
              "end_longitude": "-94.61509899999999"
          })
          .then(function(res) {
              log(res);
          })
          .error(function(err) {
              console.error(err);
          });
    }
});

Any help is appreciated.

Upvotes: 0

Views: 1040

Answers (1)

Alexander Graebe
Alexander Graebe

Reputation: 797

Please check out the README for node-uber. The method does not take a JSON object but the arguments in the method call:

uber.estimates.getPriceForRouteAsync(38.9597897, -94.606994, 39.010969, -94.615098) .then(function(res) { console.log(res); }) .error(function(err) { console.error(err); });

Also, the product ID is not needed as the /estimates/price endpoint returns an array of estimates for each product.

Upvotes: 1

Related Questions