我不知道如何使用api以xml格式发送数据。
http_post "https://crm.zoho.com/crm/private/xml/Notes/insertRecords?newFormat=1&authtoken=#{settings.api_token}&scope=crmapi&xmlData" do |req|
req.headers['Content-Type'] = 'application/xml'
req.body = {xmlData:{note:generate_note_content(ticket)}}.to_xml
end
Zoho的API要求你发布XML数据。
下面是一个使用 httparty
gem 的示例:
require 'httparty'
class ZohoCRM
include HTTParty
end
# Generated rom Zoho API
AUTH_TOKEN = '1234567890ABCDEF'
# The contact (lead, etc.) record Id
entity_id = '1234567000000012345'
api_context = 'crmapi'
xml_data = "<Notes><row no='1'><FL val='entityId'>#{entity_id}</FL><FL val='Note Title'>Zoho CRM Sample Note</FL><FL val='Note Content'>This is sample content to test Zoho CRM API</FL></row></Notes>"
response = ZohoCRM.post(
'https://crm.zoho.com/crm/private/xml/Notes/insertRecords',
body: {
newFormat: '1',
authtoken: AUTH_TOKEN,
scope: api_context,
xmlData: xml_data
}
)
引用: https://www.zoho.com/crm/help/api/insertrecords.html#Insert_notes_and_relate_to_the_primary_module
你应该尝试使用 Net/http lib。
http://ruby-doc.org/stdlib-2.0.0/libdoc/net/http/rdoc/Net/HTTP/Post.html