How to Test Surge Pricing in the Uber API Sandbox Environment (Java/Android Rides SDK)

Uber has released a Rides SDK to open its API up to developers in a slew of different packages (Java, Python, Android, and iOS). But it’s new, so hunting down answers on StackOverflow or in its docs isn’t easy.

One of the trickiest parts of Uber’s Rides SDK is handling surge pricing. You have to redirect users to a Uber page for them to confirm acceptance of surge pricing (and if it’s super high, they must complete a second authentication step). Uber’s API then returns a token to your app that enables you to make a second call to order a surge-affected ride for the user (resulting in a response with another token that your app can then use to track/cancel the ride, and so on.)

But how do you test out Uber’s surge confirmation flow in the sandbox environment?

The hardest part of handling surge wasn’t the ping-pong game of calls and responses, but finding a way to debug it. It isn’t obvious how to get the sandbox environment to return surge prices when you are making test calls. (You could try to chase down real surge areas in the production environment, but accidentally calling a ride could be costly, and the API limit is 100 calls an hour, so you might run out of calls before hitting the limit.) I eventually figured out how to consistently test surge pricing with Uber’s sandbox servers, so hopefully the below code snippets save someone some time someday!

I did a global search in the SDK files for “Sandbox”, and found the missing SDK piece I was looking for at the verrrry bottom of

The code I was looking for!

I was then able to successfully have the Uber sandbox return a given surge multiplier (e.g, 3.2x) for a given product type (e.g., UberX).

Here’s my code below, where I generate a random surge multiplier each time for a given product type rather than providing a constant number. This was a great way to make sure both the different surge flows worked without error (Uber requires an extra user authorization step when there is “high surge.”)

SandboxProductRequestParameters sandboxParams = new SandboxProductRequestParameters.Builder()
        .setSurgeMultiplier((float) (Math.random() * 5 + 1)).build();
service.updateSandboxProduct(product.getProductId(), sandboxParams).enqueue(new Callback<Void>() {
    public void onResponse(Call<Void> call, Response<Void> response) {
        Log.i("Sandbox product update","Response received");

    public void onFailure(Call<Void> call, Throwable t) {
        Log.i("Sandbox product update","Update failed");

Pretty easy, right? The whole surge flow can be a bit of a pain, but props to Uber for making sure developers show a screen that clearly shows riders the surge pricing they face. Definitely good for consumers, even if at the cost of a few extra lines of code.

If this helped, or if you have any questions, feel free to let me know by leaving a comment below!

  1 comment for “How to Test Surge Pricing in the Uber API Sandbox Environment (Java/Android Rides SDK)

  1. Yared
    January 31, 2018 at 10:41 pm

    thanx body that will help alot

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.