Jagdish
Jagdish

Reputation: 251

Uber API - requesting ride in sandbox - Receiving Error: Invalid request - validation_failed

I am working on Uber API and trying to request a ride in sandbox. I am following API guide from here - Uber API - POST Request.

StringEntity param; OR JSON looks like as below:

{
"product_id": "3145c334-25c6-462d-a2f5-70c38a165746",
"start_latitude": 41.2237329,
"start_longitude ": -73.2304860,
"end_latitude": 41.7220050,
"end_longitude": -73.3159659
}

my Java code looks like:

    String url = "https://sandbox-api.uber.com/v1/requests";
    HttpPost httpPostRequest = new HttpPost(url);
    httpPostRequest.setHeader("Authorization", "Bearer " + accessTokenModel.getAccess_token());
    httpPostRequest.setHeader("Content-Type", "application/json");
    httpPostRequest.setEntity(param);
    HttpResponse httpResponse = client.execute(httpPostRequest);

    response.getWriter().println("Status Code: " + httpResponse.getStatusLine().getStatusCode());

    br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));

    line = line1 = "";
    while ((line = br.readLine()) != null) {
            response.getWriter().println(line);
            line1 = line1 + line;
    }

I am getting, status code: 422 and error says:

{"fields":{"":"Both start_latitude and start_longitude or start_place_id are required."},"message":"Invalid request","code":"validation_failed"}

My JSON looks similar to the Uber Example suggested .. I am also setting JSON header with - Authorization Token and content type .. so not sure what am I missing ..

Can anyone spot - what am I doing wrong?

Thank you in advance

Upvotes: 1

Views: 306

Answers (1)

Alex Filatov
Alex Filatov

Reputation: 5052

There is a whitespace character appended to the start_longitude field name:

"start_longitude "
                ^ remove this space character

Upvotes: 2

Related Questions