0

I'm attempting to port code that uses the Docusign SOAP API method CreateEnvelopeFromTemplatesAndForms to the REST API. I used this page of the Rest API Reference - Send an Envelope from a Template

I've hit a roadblock in that when I try to specify a document to post to override the server template's document, I get an Unspecified error, 'An item with the same key has already been added'.

The code I'm porting over uses two inline templates and a server template.

The server template can contain one or more documents that I want to override with local documents. In the SOAP method, the documents are specified in the first inline template. The server template is specified next. And the second inline template is third in the sequence and has the recipients and custom fields. These are all added to the envelope property of the inline template.

  1. Inline Template - Docs
  2. Server Template
  3. Inline Template - Recipients and Custom Fields

In the REST api, there doesn't seem to be an envelope property for the inline template and no clear migration guide between SOAP and REST that I could find. If I exclude my 'documents' property from the inline template, the envelope sends. I get the same error if I try using the document property of compositeTemplate. Here is my web request:

POST https://demo.docusign.net/restapi/v2/accounts/ACCOUNTID/envelopes HTTP/1.1
X-DocuSign-Authentication: <DocuSignCredentials><Username>USERNAME</Username><Password>PASSWORD</Password><IntegratorKey>INTEGRATOR_KEY</IntegratorKey></DocuSignCredentials>
Accept: application/json
Content-Type: multipart/form-data; boundary=Ne737Hao~j
Host: demo.docusign.net
Content-Length: 29110
Expect: 100-continue

--Ne737Hao~j
Content-Type: application/json
Content-Disposition: form-data

{
  "status": "sent",
  "emailSubject": "Test Doc",
  "emailBlurb": "This is a test doc",
  "compositeTemplates": [
    {
      "serverTemplates": [
        {
          "sequence": "2",
          "templateId": "0b9f2226-6c2b-4c75-84c4-c1708a5c7b97"
        }
      ],
      "inlineTemplates": [
        {
          "sequence": "1",
          "documents": [
            {
              "documentId": "1",
              "name": "Donuts.pdf",
              "transformPdfFields": "false"
            }
          ]
        },
        {
          "sequence": "3",
          "recipients": {
            "signers": [
              {
                "name": "ME",
                "recipientId": "99f8f51b-ef21-46b6-a551-69c8b27159d4",
                "roleName": "Signer 1",
                "email": "MY_EMAIL_ADDRESS"
              },
              {
                "name": "ME",
                "recipientId": "bb4388f3-098e-4d3e-bcf2-20c1ae0a7c48",
                "roleName": "Signer 2",
                "email": "MY_EMAIL_ADDRESS"
              }
            ],
            "carbonCopies": [
              {
                "name": "ME",
                "recipientId": "bc65de08-984e-4f95-925d-fcf00c05966d",
                "roleName": "Auditor",
                "email": "MY_EMAIL_ADDRESS"
              }
            ]
          }
        }
      ]
    }
  ],
  "customFields": {
    "textCustomFields": [
      {
        "name": "TemplateName",
        "show": "false",
        "value": "Test Template"
      }
    ]
  }
}
--Ne737Hao~j
Content-Type: application/pdf
Content-Disposition:file; file="Donuts.pdf"; documentId=1
Content-Transfer-Encoding: binary

%PDF-1.6
REST OF PDF BYTES
%%EOF

--Ne737Hao~j--

Thanks in advance.

I've also already looked at Incorrectly applied server templates with multiple composite templates and Adding documents to envelopes using composite templates in DocuSign with little luck.

Update

After trying the answer by WTP API below, I experimented some more. I found that the envelope would send with the correct document if I either include the base64 of the document or if I simplified the headers sent with the document bytes to just be Content-Disposition:documentId=1 instead of all the headers shown here: Docusign Rest API - Send an Envelope From a Template

POST https://demo.docusign.net/restapi/v2/accounts/ACCOUNTID/envelopes HTTP/1.1
X-DocuSign-Authentication: <DocuSignCredentials><Username>USERNAME</Username><Password>PASSWORD</Password><IntegratorKey>INTEGRATOR_KEY</IntegratorKey></DocuSignCredentials>
Accept: application/json
Content-Type: multipart/form-data; boundary=Ne737Hao~j
Host: demo.docusign.net
Content-Length: 29110
Expect: 100-continue

--Ne737Hao~j
Content-Type: application/json
Content-Disposition: form-data

{
  "status": "sent",
  "emailSubject": "Test Doc",
  "emailBlurb": "This is a test doc",
  "compositeTemplates": [
    {
      "serverTemplates": [
        {
          "sequence": "2",
          "templateId": "0b9f2226-6c2b-4c75-84c4-c1708a5c7b97"
        }
      ],
      "inlineTemplates": [
        {
          "sequence": "1",
          "documents": [
            {
              "documentId": "1",
              "name": "Donuts.pdf",
              "transformPdfFields": "false"
            }
          ]
        },
        {
          "sequence": "3",
          "recipients": {
            "signers": [
              {
                "name": "ME",
                "recipientId": "99f8f51b-ef21-46b6-a551-69c8b27159d4",
                "roleName": "Signer 1",
                "email": "MY_EMAIL_ADDRESS"
              },
              {
                "name": "ME",
                "recipientId": "bb4388f3-098e-4d3e-bcf2-20c1ae0a7c48",
                "roleName": "Signer 2",
                "email": "MY_EMAIL_ADDRESS"
              }
            ],
            "carbonCopies": [
              {
                "name": "ME",
                "recipientId": "bc65de08-984e-4f95-925d-fcf00c05966d",
                "roleName": "Auditor",
                "email": "MY_EMAIL_ADDRESS"
              }
            ]
          }
        }
      ]
    }
  ],
  "customFields": {
    "textCustomFields": [
      {
        "name": "TemplateName",
        "show": "false",
        "value": "Test Template"
      }
    ]
  }
}
--Ne737Hao~j
Content-Disposition:documentId=1

%PDF-1.6
REST OF PDF BYTES
%%EOF

--Ne737Hao~j--
Community
  • 1
  • 1
Ed H
  • 19
  • 4

1 Answers1

2

The "documents" node and "recipients" should be within the same inline template.

Below is the correct JSON body that works for me:

{
    "status": "sent",
    "emailSubject": "Test Doc",
    "emailBlurb": "This is a test doc",
    "compositeTemplates": [
        {
            "serverTemplates": [
                {
                    "sequence": "2",
                    "templateId": "0b9f2226-6c2b-4c75-84c4-c1708a5c7b97"
                }
            ],
            "inlineTemplates": [
                {
                    "sequence": "1",
                    "documents": [
                        {
                            "documentId": "1",
                            "name": "Donuts.pdf",
                            "transformPdfFields": "false"
                        }
                    ],
                    "recipients": {
                        "signers": [
                            {
                                "name": "ME",
                                "recipientId": "99f8f51b-ef21-46b6-a551-69c8b27159d4",
                                "roleName": "Signer 1",
                                "email": "MY_EMAIL_ADDRESS"
                            },
                            {
                                "name": "ME",
                                "recipientId": "bb4388f3-098e-4d3e-bcf2-20c1ae0a7c48",
                                "roleName": "Signer 2",
                                "email": "MY_EMAIL_ADDRESS"
                            }
                        ],
                        "carbonCopies": [
                            {
                                "name": "ME",
                                "recipientId": "bc65de08-984e-4f95-925d-fcf00c05966d",
                                "roleName": "Auditor",
                                "email": "MY_EMAIL_ADDRESS"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "customFields": {
        "textCustomFields": [
            {
                "name": "TemplateName",
                "show": "false",
                "value": "Test Template"
            }
        ]
    }
}
WTP API
  • 546
  • 3
  • 16
  • I still get the same error after merging the two templates. I tried some variations on it as well. If I exclude the documents from the JSON but leave the document bytes, it sends just fine. If I exclude the name or or document idm I get errors telling me to include them. I also tried swapping the sequence number for the server and inline templates but that also gives me the key error. – Ed H May 12 '14 at 16:05
  • If I add documentBase64 to the inline template document it works. – Ed H May 12 '14 at 17:05
  • I got it working with document bytes as well. See the edit to my question. Thank you, your reply helped me to figure out the answer but it only works if you don't try to replace the server template document. – Ed H May 12 '14 at 17:14