Ruby 写发票的 Rest-Client API

Ruby Rest-Client for writing invoice API

我是 Ruby 的新手,正在尝试使用 Ruby gem 'rest-client' 访问我的会计系统的 REST API,e -conomic.com。我可以通过令牌连接,例如获取客户详细信息 - 到目前为止一切顺利。

但是,我正在努力弄清楚如何 POST 从而创建一个新的客户条目,例如地址、姓名、邮件等。特别是,我希望获取代码以包含我的身份验证令牌详细信息(即下面的 hHeader 的内容),同时还包含客户详细信息的有效负载。

有关通过 REST 创建客户的详细信息 API: https://restdocs.e-conomic.com/#post-customer-groups

关于 rest-client 的详细信息 ruby gem: https://github.com/rest-client/rest-client

我在 Atom 编辑器中 运行 Ruby 2.3.3 Windows 7。 我的代码如下:

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)

非常感谢您的意见!

马丁

您输入了错误的 api 文档,它是 POST 客户,而不是 POST 客户组。您应该发送 post 和:

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