I'm trying to send a POST request to an api with a hash as the parameters of the request. The api in question is freshdesk's api. I'm using rails 4.
They require that i send a request in this form:
Code
{
"helpdesk_ticket":{
"description":"Some details on the issue ...",
"subject":"Support needed..",
"email":"[email protected]",
"priority":1, "status":2
},
"cc_emails":"[email protected],[email protected]"
}
Sample Curl
curl -u [email protected]:test -H "Content-Type: application/json" -d '{ "helpdesk_ticket": { "description": "Details about the issue...", "subject": "Support Needed...", "email": "[email protected]", "priority": 1, "status": 2 }, "cc_emails": "[email protected],[email protected]" }' -X POST http://domain.freshdesk.com/helpdesk/tickets.json
This is currently what I have
Controller
def create
email = params[:email]
description = params[:description]
subject = params[:subject]
payload = [{"helpdesk_ticket" => { 'email' => email, 'description' => description, 'subject' => subject, 'priority' => 1, 'status' => 2}}].to_json
trololol = Freshdesk.post('/helpdesk/tickets.json',
:body => payload
)
debugger
redirect_to "/support"
end
class Freshdesk
include HTTParty
@apikey = "Somethingladida"
format :json
base_uri "http://genericname.freshdesk.com/"
basic_auth @apikey, ""
end
View
=form_tag support_index_path do
=label_tag :email
=text_field_tag :email,params[:email]
=label_tag :description
=text_field_tag :description
=label_tag :subject
=text_field_tag :subject
=submit_tag "Submit", class:"button"
The main problem is this: I'm getting a 500 internal server error, so I'm presuming that the request that i'm trying to craft is not in the format that the freshdesk api requires
Cheers! :)