首页 文章

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

提问于
浏览
0

我正在使用docusign_rest 宝石来与 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 宝石在自定义信封字段中显示以下内容:

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

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

1 回答

  • 1

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

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

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

相关问题