Uber API GET/estimates/price response surge_multip

2019-08-04 03:13发布

问题:

today, I found GET/estimates/price end point have a change, surge_multiplier disappeared, is to say, price has been fixed, no more surge?

回答1:

Surging is based on the particular location and product setup - so if you try following request for example:

https://sandbox-api.uber.com//v1.2/estimates/price?start_latitude=-33.865535736083984&start_longitude=151.1958770751953&end_latitude=-33.88345718383789&end_longitude=151.0906982421875

"prices": [
{
  "localized_display_name": "uberX",
  "distance": 7.76,
  "display_name": "uberX",
  "product_id": "2d1d002b-d4d0-4411-98e1-673b244878b2",
  "high_estimate": 35,
  "surge_multiplier": 1,
  "minimum": 9,
  "low_estimate": 26,
  "duration": 1260,
  "estimate": "A$26-35",
  "currency_code": "AUD"
},

If you try it for different location:

start_latitude=37.7752315&start_longitude=-122.418075&end_latitude=37.7752415&end_longitude=-122.518075

You will get response without 'surge_multiplier' parameter:

{
  "localized_display_name": "uberXL",
  "distance": 6.62,
  "display_name": "uberXL",
  "product_id": "821415d8-3bd5-4e27-9604-194e4359a449",
  "high_estimate": 28,
  "low_estimate": 22,
  "duration": 1380,
  "estimate": "$22-28",
  "currency_code": "USD"
},

For more info on surging please read our documetation

EDIT done on 02/15/2018:

If you are using v1.2 request - response we are getting is based on the product setup. If the product used in the estimate request is configured to have "upfront_fare_enabled": true then we will get one fare_id - instead of estimate. So this is expected as in v1.2 with upfront_fare_enabled: true there will never be surge information (as you get a real fare + fare_id).

Please check following sentence from our documentation on "POST /v1.2/requests/estimate" endpoint:

You should use this endpoint to get an upfront fare before requesting a ride. In some products upfront fares are not enabled so you can use this endpoint to determine if surge pricing is in effect for the product/location. Do this before attempting to make a ride request so that you can preemptively have a user confirm surge by sending them to the surge_confirmation_href provided in the response. This endpoint will either return an upfront fare (in the fare key) or a range estimate (in the estimate key) depending on the configuration of the product.

So the response you are getting back depends on product configuration specifically: "upfront_fare_enabled" field. If there is upfront fare setup (upfront_fare_enabled = true) then there will not be "surge_confirmation_href" available in the response - and response type will be one "fare": {} response - example of this is below:

{
  "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
}

As you can see there is no "surge_confirmation_href" available.

If your product has "upfront_fare_enabled": false you will get estimate response with surge_confirmation_id and surge_confirmation_href as shown below:

{
  "estimate": {
    "surge_confirmation_href": "https:\/\/api.uber.com\/v1\/surge-confirmations\/7d604f5e",
    "high_estimate": 11,
    "surge_confirmation_id": "7d604f5e",
    "minimum": 5,
    "low_estimate": 8,
    "fare_breakdown": [
      {
        "low_amount": 1.25,
        "high_amount": 1.25,
        "display_amount": "1.25",
        "display_name": "Base Fare"
      },
      {
        "low_amount": 1.92,
        "high_amount": 2.57,
        "display_amount": "1.92-2.57",
        "display_name": "Distance"
      },
      {
        "low_amount": 2.50,
        "high_amount": 3.50,
        "display_amount": "2.50-3.50",
        "display_name": "Surge x1.5"
      },
      {
        "low_amount": 1.25,
        "high_amount": 1.25,
        "display_amount": "1.25",
        "display_name": "Booking Fee"
      },
      {
        "low_amount": 1.36,
        "high_amount": 1.81,
        "display_amount": "1.36-1.81",
        "display_name": "Time"
      }
    ],
    "surge_multiplier": 1.5,
    "display": "$8-11",
    "currency_code": "USD"
  },
  "trip": {
    "distance_unit": "mile",
    "duration_estimate": 480,
    "distance_estimate": 1.95
  },
  "pickup_estimate": 2
}

And finally, if you update the product to have "surge_multiplier" > 1 and product have "upfront_fare_enabled = true" you will get "fare" response - but you will not know that surging is in place - until you do ride request. In this case, you will get the response with: "status": 409 and "title": "Surge pricing is currently in effect for this product." and "surge_confirmation" info that contains "href": "https://sandbox-api.uber.com/surge-confirmations/ride_request_id". So in order to complete your ride request - you need to redirect your user to that URL - and user needs to confirm surging. After that, you will be able to create new ride request.

resposne->

{
  "meta": {
    "surge_confirmation": {
      "href": "https://sandbox-api.uber.com/surge-confirmations/48165d0e-f2f4-457d-98d0-058a31b15cd7",
      "expires_at": 1510684778,
      "multiplier": 1.2,
      "surge_confirmation_id": "48165d0e-f2f4-457d-98d0-058a31b15cd7"
    }
  },
  "errors": [
    {
      "status": 409,
      "code": "surge",
      "title": "Surge pricing is currently in effect for this product."
    }
  ]
}


标签: uber-api