Search code examples
pythonuber-api

No exact amount estimate price for UberX


Currently within the app, requesting a UberX instantly give you a exact quote price but in the Python API, I couldn't find it. I can only find the range of the cost. Where is the exact quote at? enter image description here


Solution

  • Try to use "POST /v1.2/requests/estimate"

    Example Request

    curl -X POST \
     -H 'Authorization: Bearer <TOKEN>' \
     -H 'Accept-Language: en_US' \
     -H 'Content-Type: application/json' \
     -d '{
       "start_latitude": 37.7752278,
       "start_longitude": -122.4197513,
       "end_latitude": 37.7773228,
       "end_longitude": -122.4272052
     }' "https://api.uber.com/v1.2/requests/estimate"
    

    I suggest you use "product_id" as well - to get the price for the product you need. Otherwise, if none is provided, it will default to the cheapest product for the given location.

    You will get the response like:

    {
    "fare": {
    "value": 5.73,
    "fare_id": "d30e732b8bba22c9cdc10513ee86380087cb4a6f89e37ad21ba2a39f3a1ba960",
    "expires_at": 1476953293,
    "display": "$5.73",
    "currency_code": "USD",
    "breakdown": [
     {
       "type": "promotion",
       "value": -2.00,
       "name": "Promotion"
     },
     {
       "type": "base_fare",
       "notice": "Fares are slightly higher due to increased demand",
       "value": 7.73,
       "name": "Base Fare"
     }
     ]
    },
    "trip": {
    "distance_unit": "mile",
    "duration_estimate": 540,
    "distance_estimate": 2.39
    },
    "pickup_estimate": 2
    }
    

    Related to Pyton SDK - Please check: https://developer.uber.com/docs/riders/ride-requests/tutorials/api/python. You need to authenticate your user, and then get a product you want to use, and then get upfront fare (if product support this: upfront_fare_enabled field set to true). And after that you can book a ride. Code how to do it is in doc link I have sent as well:

    # Get products for a location
    response = client.get_products(37.77, -122.41)
    products = response.json.get('products')
    
    product_id = products[0].get('product_id')
    
    # Get upfront fare and start/end locations
    estimate = client.estimate_ride(
    product_id=product_id,
    start_latitude=37.77,
    start_longitude=-122.41,
    end_latitude=37.79,
    end_longitude=-122.41,
    seat_count=2
    )
    fare = estimate.json.get('fare')
    
    # Request a ride with upfront fare and start/end locations
    response = client.request_ride(
    product_id=product_id,
    start_latitude=37.77,
    start_longitude=-122.41,
    end_latitude=37.79,
    end_longitude=-122.41,
    seat_count=2,
    fare_id=fare['fare_id']
    )
    
    request = response.json
    request_id = request.get('request_id')
    
    # Request ride details using `request_id`
    response = client.get_ride_details(request_id)
    ride = response.json
    
    # Cancel a ride
    response = client.cancel_ride(request_id)
    ride = response.json