使用 Docusign REST 的自定义信封字段 API

Custom envelope fields using Docusign REST API

我在我的 rails 应用程序中使用 docusign_rest gem 与 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

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

您的 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 正在将您的 _ 转换为驼峰式字符串。如果这没有发生,那也需要改变。