【发布时间】:2014-05-06 05:02:25
【问题描述】:
我正在尝试将 POST 请求发送到带有哈希作为请求参数的 api。有问题的api是freshdesk的api。我正在使用 Rails 4。
他们要求我以这种形式发送请求:
代码
{
"helpdesk_ticket":{
"description":"Some details on the issue ...",
"subject":"Support needed..",
"email":"hulk@outerspace.com",
"priority":1, "status":2
},
"cc_emails":"superman@marvel.com,avengers@marvel.com"
}
示例卷曲
curl -u user@yourcompany.com:test -H "Content-Type: application/json" -d '{ "helpdesk_ticket": { "description": "有关问题的详细信息...", "subject": "需要支持...", "email": “hulk@outerspace.com”、“优先级”:1、“状态”:2 }、“cc_emails”: “superman@marvel.com,avengers@marvel.com”}' -X POST http://domain.freshdesk.com/helpdesk/tickets.json
这是我目前拥有的
控制器
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
查看
=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"
主要问题是:我收到 500 内部服务器错误,所以我假设我尝试制作的请求不是freshdesk api 要求的格式
干杯! :)
【问题讨论】:
标签: ruby-on-rails json api post request