divergent divergent - 3 months ago 15
Ruby Question

"Unable to parse JSON" error from Uber API

(Similar question but different language/implementation - Uber API - requests endpoint cannot read read json)

I am getting the following error from trying to make a post request to the

/v1/requests
endpoint of the UBER API.


{"message":"Unable to parse JSON in request body.","code":"invalid_json"}


Here is my code:


response = access_token.post('https://sandbox-api.uber.com/v1/requests', {params: {:start_latitude => 37.761492, :start_longitude => -122.423941, :end_latitude => 37.775393, :end_longitude => -122.417546}, :headers => {'Content-Type' => 'application/json'}})


As you can see I am using the
[oAuth2 gem][1]
to make the API calls. How can I format the query so that the JSON is acceptable to the API? I can't seem to find any documentation that sheds light on this.

Any help will be appreciated. Thanks.

Answer

Looks like you're not using the oauth2 gem correctly. See the top answer to this question Ruby on Rails: how to use OAuth2::AccessToken.post?

The body parameter is for the body of a POST. You're using params which is for query parameters.