【问题标题】:Ruby Rest-Client for writing invoice APIRuby Rest-Client 用于编写发票 API
【发布时间】:2017-03-05 18:20:45
【问题描述】:

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

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

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

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

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

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)

您的意见将不胜感激!

马丁

【问题讨论】:

    标签: ruby rest post rest-client


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      • 2021-09-13
      • 2023-04-09
      • 1970-01-01
      相关资源
      最近更新 更多