简体   繁体   中英

Custom envelope fields using Docusign REST API

I'm using the docusign_rest gem to integrate with the Docusign REST API in my rails application. I have created a custom envelope field in the Docusign admin called SFID. I need to pass an ID into SFID inside of the envelope. I'm getting the following error with my JSON code:

{"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."}

My controller code:

@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: [
  ...

The Docusign API explorer says the following is the correct way to push an envelope custom field:

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

The Docusign_rest gem says the following on custom envelope fields:

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

What formatting changes to I need to make to my controller code to get it to successfully push a custom envelope field?

You have an extra array in your customFields node.

Remove the [] array from your 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: [
  ...

Also I'm assuming that your client.create_envelope_from_template is converting your _'s into a camelCased string. if that is not happening, then that also needs to change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM