Reputation: 611
I'm running a simple Sinatra app where I need to query some data and send a POST via JSON to a webhook URL for processing. I'm not sure how to properly format the records I've retrieved for HTTParty.
The contacts are printing to /account/{account_id}/contacts.json how I want them, they data just isn't being sent successfully.
app.rb
get "/account/:account_id/contacts.json" do
@contacts = Contact.where("sfid = ?", params[:account_id])
HTTParty.post("https://hooks.webapp.com/hooks/catch/387409/1us4j3/",
{
:body => [ @contacts ].to_json,
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
})
@contacts.to_json
end
Upvotes: 0
Views: 106
Reputation: 727
It seems the error is
2.3.1/lib/ruby/2.3.0/net/http/generic_request.rb:183:in `send_request_with_body'
It does not found any body in your request. You are sending the parameters body and head inside a hash.
Try this:
get "/account/:account_id/contacts.json" do
@contacts = Contact.where("sfid = ?", params[:account_id])
HTTParty.post("https://hooks.webapp.com/hooks/catch/387409/1us4j3/",
:body => @contacts.to_json,
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
)
@contacts.to_json
end
You can checkout this post also for any more information regarding HTTP post Here
Hope this helps..
Upvotes: 1