How can I implement this POST request using HTTParty? How can I implement this POST request using HTTParty? curl curl

How can I implement this POST request using HTTParty?


Just a guess, but it looks like you're passing a hash in the body when JSON is expected.

Try replacing the :body declaration with:

:body => [{ "amount" => "0.25",              "platform" => "gittip",              "username" => "whit537" }].to_json

Edit:I suggested the to_json serializer, but misplaced it by putting it after the hash instead of the array and removing the array altogether. The example uses multiple records, so the array is necessary.

After looking at this thread, it looks like Gittip is picky about the accept header.

:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}

So, the full suggestion is:

HTTParty.post("https://www.gittip.com/#{user}/tips.json",  {     :body => [ { "amount" => "0.25", "platform" => "gittip", "username" => "whit537" } ].to_json,    :basic_auth => { :username => api_key },    :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}  })