2017-03-05 64 views
0

我是Ruby的新手,嘗試使用Ruby gem'rest-client'來訪問我的會計系統e-conomic.com的REST API。我可以通過令牌和例如獲取客戶詳細信息 - 迄今爲止,非常好。Ruby Rest-Client用於編寫發票API

但是,我正在努力弄清楚如何POST,從而創建一個新的客戶條目,例如,地址,姓名,郵件等。特別是,我希望得到的代碼都包含我的身份驗證令牌的詳細信息(即下面的hHeader的內容),同時還包含客戶詳細信息的有效內容。 https://github.com/rest-client/rest-client

我在Atom編輯器在Windows 7上運行的Ruby 2.3.3:關於其他客戶端紅寶石寶石 https://restdocs.e-conomic.com/#post-customer-groups

詳情:關於通過REST API客戶創造

詳細。我的代碼如下:

Dir.chdir 'C:\Ruby23\bin' 
require 'rest-client' 
require 'rconomic' 
require 'json' 

hHeader = {"X-AppSecretToken" => 'tokenID1_sanitized', "X-AgreementGrantToken" => 'tokenID2_sanitized', "Content-Type" => 'application/json'} 

hCustomer = RestClient.get("https://restapi.e-conomic.com/customers/5", hHeader) # => creates a response showing customer 5 (shown for example of GET) 

您的意見將不勝感激!

馬丁

回答

2

你把錯誤的API文檔,它的郵政客戶,而不是郵政客戶羣體。你應該發送郵件:

body = {'address' => 'Example Street', 'name' => 'John Doe'}.to_json 
RestClient.post "https://restapi.e-conomic.com/customers/", body, hHeader) 
+0

真棒,這工作 - 非常感謝! – Martin