cfg26
cfg26

Reputation: 11

Uber API: Request Endpoint Yields Error Not Supported

I saw another post like this on here before but it wasn't of much help. Anyway, I have all of the OAuth steps completed, and have gotten my access token. Below is the error I am recieving -

{"message":"Not supported","code":"not_found"}

I have tried using the URl manually and have tried using POST. Here is the URL I tried -

http://sandbox-api.uber.com/v1/requests?access_token=m5MunZjxNVCXbg1p4DXPQjK76DYFaz&product_id=653e6788-871e-4c63-a018-d04423f5b2f7&start_latitude=40.11690903&start_longitude=-75.01428223&end_latitude=40.650729&end_longitude=-74.0095369

After getting the error, I tried a POST (thanks to another post I saw on here) to sandbox requests which results in 301 Moved Permanently Response.

The code for POST I used I also found on here which I will post below (I'm pretty new to all of this).

URL url4 = new URL("http://sandbox-api.uber.com/v1/requests");
Map<String,Object> params2 = new LinkedHashMap<>();
params2.put("access_token", AccessToken);
params2.put("product_id", productID);
params2.put("start_latitude", latitude);
params2.put("start_longitude", longitude) ;
params2.put("end_latitude", endLatitude);
params2.put("end_longitude", endLongitude);
StringBuilder postData = new StringBuilder();

for (Map.Entry<String,Object> param : params2.entrySet()) {
    if (postData.length() != 0) postData.append('&');
        postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
        postData.append('=');
                                      postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));        }                                       
            byte[] postDataBytes = postData.toString().getBytes("UTF-8");

HttpURLConnection conn = (HttpURLConnection)url4.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-formurlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));         
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);

Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
for ( int c = in.read(); c != -1; c = in.read() )
    System.out.print((char)c);

So am I just doing something fundamentally wrong here? I have gotten estimates/products to work so I am not sure what I am doing wrong.

Apologize for the weird formatting, new here and it doesn't seem to want to let me indent certain lines.

Thanks

Upvotes: 1

Views: 138

Answers (1)

Alec
Alec

Reputation: 561

There are a few issues with the code that you provided:

  • The sandbox endpoint uses HTTPS (as opposed to HTTP)
  • You should provide your access token via the Authorization header, as opposed to a URL parameter.
  • Content-Type value should be application/json.

Upvotes: 1

Related Questions