Tuesday, 20 August 2013

Unable to decode request as valid JSON using RUBY

Unable to decode request as valid JSON using RUBY

I am making the following API GET request, using ruby 1.9.3 and the
httparty gem:
uri= HTTParty.post("www.surveys.com/api/v2/contacts",
:basic_auth => auth,
:headers => { 'ContentType' => 'application/json' },
:body => {
"custom_test" => test,
"name" => firstname,
"email" => emailaddress
}
)
The variables auth,test,firstname, and emailaddress are valid. This is the
response I am receiving back from my request:
{
"code": "invalid_json",
"description": "Request sent with Content-Type: application/json but was
unable to decode request body as valid json.",
"success": false
}
500
#<Net::HTTPInternalServerError:0x007fe4eb98bde0>
What is wrong with the way I am posting this JSON request?
EDIT: It's probably worth noting that the API allows you to define custom
attributes to a contact, hence the "custom_test" attribute in the body.

No comments:

Post a Comment