【问题标题】:Custom envelope fields using Docusign REST API使用 Docusign REST API 的自定义信封字段
【发布时间】:2015-06-24 00:07:29
【问题描述】:

我正在使用docusign_rest gem 与我的rails 应用程序中的Docusign REST API 集成。我在 Docusign 管理员中创建了一个名为 SFID 的自定义信封字段。我需要将一个 ID 传递到信封内的 SFID 中。我的 JSON 代码出现以下错误:

{"errorCode"=>"INVALID_REQUEST_BODY", "message"=>"The request body is missing or improperly formatted. Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'API_REST.Models.v2.customFields' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath 'customFields', line 1, position 1073."}

我的控制器代码:

@envelope_response = client.create_envelope_from_template(
  status: 'sent',
  email: {
    subject: "The test email subject envelope",
    body: ""
  },
  template_id: '90B58E8F-xxxxx',
  custom_fields: [
    {
      textCustomFields: [
        {
          name: 'SFID',
          value:'12345',
          required: 'false',
          show: 'true'
        }
      ]
    }
  ],
  signers: [
  ...

Docusign API 浏览器说以下是推送信封自定义字段的正确方法:

{
  "customFields": {
    "textCustomFields": [
      {
        "value": "0101010101",
        "required": "true",
        "show": "true",
        "name": "SFID"
      },
      {
        "required": "true",
        "show": "true"
      }
    ]
  }
}

Docusign_rest gem 在自定义信封字段上显示以下内容:

customFields  - (Optional) A hash of listCustomFields and textCustomFields.
    #                 Each contains an array of corresponding customField hashes.
    #                 For details, please see: http://bit.ly/1FnmRJx

我需要对控制器代码进行哪些格式更改才能使其成功推送自定义信封字段?

【问题讨论】:

    标签: ruby-on-rails json ruby-on-rails-4 docusignapi


    【解决方案1】:

    您的 customFields 节点中有一个额外的数组。

    从您的 custom_fields 中删除 [] 数组:

    @envelope_response = client.create_envelope_from_template(
      status: 'sent',
      email: {
        subject: "The test email subject envelope",
        body: ""
      },
      template_id: '90B58E8F-xxxxx',
      custom_fields: 
        {
          textCustomFields: [
            {
              name: 'SFID',
              value:'12345',
              required: 'false',
              show: 'true'
            }
          ]
        },
      signers: [
      ...
    

    我还假设您的 client.create_envelope_from_template 正在将您的 _ 转换为驼峰式字符串。如果这没有发生,那也需要改变。

    【讨论】:

    • 按预期工作。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多