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

时间:2015-06-24 00:07:30

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

我使用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

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

1 个答案:

答案 0 :(得分: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正在将您的_转换为camelCased字符串。如果没有发生,那么也需要改变。