I'm trying to add documents to a composite template using the docusign api and the documents aren't loading into the envelope the way I would expect it to. I currently have my code working with a test json where I add documents without using composite templates and it works perfectly. It seems the composite templates skip right over the documents however. Here's how I'm creating it:
{
"emailSubject": "Test Email Subject_FA",
"emailBlurb": "Test Email Body_FA",
"status": "created",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"email": "test1#yahoo.com",
"name": "test1",
"recipientId": "1",
"routingOrder": "1",
"roleName": "Client 1"
},
{
"email": "test2#gmail.com",
"name": "test2",
"recipientId": "2",
"routingOrder": "2",
"roleName": "Client 2"
}
],
"documents": [
{
"transformPdfFields": "false",
"name": "test0.pdf",
"documentId": "1"
}
]
}
}
]
},
{
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"email": "test1#yahoo.com",
"name": "test1",
"recipientId": "1",
"routingOrder": "1",
"roleName": "Client 1"
},
{
"email": "test2#gmail.com",
"name": "test2",
"recipientId": "2",
"routingOrder": "2",
"roleName": "Client 2"
}
],
"documents": [
{
"transformPdfFields": "false",
"name": "test1.pdf",
"documentId": "2"
}
]
}
}
]
}
]
}
This is a little test I'm doing so I understand this is impractical. But what I'm trying to understand is why this wouldn't add documents to the envelope. The request below does what I'm trying to do above.
{
"emailSubject": "Test Email Subject_FA",
"emailBlurb": "Test Email Body_FA",
"status": "created",
"documents": [
{
"name": "test0.pdf",
"documentId": "1"
},
{
"name": "test1.pdf",
"documentId": "2"
},
{
"name": "test2.pdf",
"documentId": "3"
}
],
"recipients": {
"signers": [
{
"email": "test1#yahoo.com",
"name": "test1",
"recipientId": "1",
"clientUserId": "1",
"signerName": "test1",
"defaultRecipient": "true",
"defaultRecipientSpecified": "true",
"routingOrder": "1"
},
{
"email": "test2#gmail.com",
"name": "test2",
"recipientId": "2",
"clientUserId": "2",
"signerName": "test2",
"routingOrder": "2"
}
]
}
}
Does anybody know why my envelope for the composite template won't load the documents?
Thank you in advance!
UPDATE:
Here's my request for the composite template:
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"emailSubject": "Test Email Subject_FA",
"emailBlurb": "Test Email Body_FA",
"status" : "created",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence": "1",
"recipients":
{
"signers": [
{
"email": "test1#yahoo.com",
"name": "test1",
"recipientId": "1"
},
{
"email": "test2#gmail.com",
"name": "test2",
"recipientId": "2"
}
],
"document":
{
"name": "test0",
"documentId": "1",
"fileExtension": "pdf"
}
}
}
]
},
{
"inlineTemplates": [
{
"sequence": "2",
"recipients": {
"signers": [
{
"email": "test1#yahoo.com",
"name": "test1",
"recipientId": "1"
},
{
"email": "test3#yahoo.com",
"name": "test3",
"recipientId": "2"
}
],
"document":
{
"name": "test1",
"documentId": "2",
"fileExtension": "pdf"
}
}
}
]
}
]
}
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="test0.pdf"; documentid="1"
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="test1.pdf"; documentid="2"
--MY_BOUNDARY--
I've adjusted my document to use name and fileDxtension, so I left out the .pdf extension on the fileName as that seems to be another method of implementing this. I've tried it both ways and had no luck.
In the request JSON you posted, you're specifying "documents" (plural) as a collection/array of document objects -- which isn't correct. Each Composite Template item within the compositeTemplates array can only contain, at most, a single document. This means that the JSON syntax for specifying the document within a Composite Template is as follows:
"document": {
"documentId": 1,
"name": "test1.pdf"
}
i.e., document is singular, and it's an object (not an array of objects). Full request syntax of the 'composite templates' JSON request is shown in the answer of your prior question:
How do I apply a template to a document using Docusign REST API.
RE the "UPDATE" to your question:
In the JSON portion of the request that you've posted under "UPDATE", I notice that you have included document inside of the recipients object (which is contained within the inlineTemplates object) -- this is not the correct location for document. Compare your JSON structure closely with the following (correct) structure, and adjust your request accordingly. Essentially, document must be a peer of inlineTemplates -- not located within inlineTemplates.
POST https://demo.docusign.net/restapi/v2/accounts/ACCOUNTNBR/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"USERNAME","Password":"PASSWORD","IntegratorKey":"INTEGRATORKEY"}
Content-Type: multipart/form-data; boundary=MY_BOUNDARY
Accept: application/json
Host: demo.docusign.net
Content-Length: 162100
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"status" : "sent",
"emailSubject" : "Test Envelope Subject",
"emailBlurb" : "Test Envelope Blurb",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence" : 1,
"recipients": {
"signers" : [{
"email": "abbysemail#outlook.com",
"name": "Abby Abbott",
"recipientId": "1"
}]
}
}],
"document": {
"documentId": 1,
"name": "CustomerAgreement",
"fileExtension": "pdf"
}
}]
}
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="CustomerAgreement.pdf"; documentid="1"
<document bytes removed>
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="Invoice.pdf"; documentid="2"
<document bytes removed>
--MY_BOUNDARY--
Related
Is it possible to transform PDF text field (not signature field) to initialHereTab ?
Note : it works well with signature field but not with text filed
Here is my JSON request:
{
"compositeTemplates": [
{
"compositeTemplateId": "1",
"document": {
"documentBase64": "PDFDocumentInBase64",
"documentId": "1",
"fileExtension": "pdf",
"name": "Merge_2020310203633868.pdf",
"transformPdfFields": "true"
},
"inlineTemplates": [
{
"recipients": {
"signers": [
{
"clientUserId": "1",
"email": "myEmail#email.ca",
"name": "Paul J Smith",
"recipientId": "1",
"tabs": {
"initialHereTabs": [
{
"tabLabel": "\\applicant1\\*"
}
]
}
}
]
},
"sequence": "1"
}
]
}
],
"emailSubject": "Please sign this legal form at your convenience",
"status": "created"
}
Yes, per the documentation:
If: Adobe name contains DocuSignInitialHere or eSignInitialHere
Then: a DocuSign Initials tab will be created
My goal is to make SignHereTab location and size the same as one of my Pdf Form Field. Docusign guide
tells me that I can transform Pdf Form fields into DocuSign tabs. And according to the guide I shoud use CompositeTempates.
I have two recipients and two Pdfs. One pdf should be signed by both recipients, the second pdf should be signed by the first. Here is JSON example of envelop. I'm usign CreateEnvelop method from Docusign.eSign.dll (https://www.nuget.org/packages/DocuSign.eSign.dll/)
{
"compositeTemplates": [
{
"document": {
"documentBase64": "base64 data",
"documentId": "1",
"name": "MainPart.pdf",
"transformPdfFields": "True"
},
"inlineTemplates": [
{
"recipients": {
"signers": [
{
"accessCode": "1239",
"email": "insured#gmail.com",
"name": "Insured ",
"recipientId": "1",
"routingOrder": "1",
"tabs": {
"signHereTabs": [
{
"recipientId": "1",
"tabLabel": "insured_sign_parta\\*"
}
]
}
},
{
"accessCode": "1212",
"email": "owner#gmail.com",
"name": "Owner",
"recipientId": "2",
"routingOrder": "2",
"tabs": {
"signHereTabs": [
{
"recipientId": "2",
"tabLabel": "owner_sign_parta\\*"
}
]
}
}
]
},
"sequence": "1"
}
]
},
{
"document": {
"documentBase64": "base64 data",
"documentId": "2",
"name": "AdditionalPart.pdf",
"transformPdfFields": "True"
},
"inlineTemplates": [
{
"recipients": {
"signers": [
{
"accessCode": "1239",
"email": "insured#gmail.com",
"name": "Insured",
"recipientId": "1",
"routingOrder": "1",
"tabs": {
"signHereTabs": [
{
"recipientId": "1",
"tabLabel": "insured_sign_parta\\*"
}
]
}
}
]
},
"sequence": "2"
}
]
}
],
"emailBlurb": "Email Text",
"emailSubject": "Subject",
"status": "sent"
}
When I open documents SignHereTabs doesn't appear :(
Could anybody help me, please? What am I doing wrong?
I have seen tutorials from Docusign website and all related issues on StackOverflow, but still it didn't help. I've been investigating this issue for almost two days and I got nothing...
tabs should have a documentId as well as a recipientId so that they can refer to both the recipient that needs to sign them and the specific document that they should be in.
see here for full reference - https://developers.docusign.com/esign-rest-api/reference/Envelopes/EnvelopeDocumentTabs
This is my JSON code so far:
{
"status": "sent",
"emailSubject": "This is an api Demo Doc, sent for signature",
"recipients": {
"carbonCopies": [
{
"email": "nila#gmail.com",
"name": "Nilashree",
"recipientId": "2"
}
],
"signers": [
{
"email": "{{signer1Email}}",
"name": "Nilashree Nandkumar shirodkar",
"recipientId": "1"
}
]
},
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"email": "nshiro2#students.towson.edu",
"name": "Nila Joseph",
"recipientId": "1",
"defaultRecipient": "true"
}
]
}
}
],
"documents": {
"documentId": "1",
"name": "application_form.pdf",
"transformPdfFields": "true",
"documentBase64": "{{}}"
}
}
]
}
But I am getting the following error:
"errorCode": "ENVELOPE_IS_INCOMPLETE",
"message": "The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line."
Can anyone please let me know what am I doing wrong?
Why are you using a composite template? Perhaps you are planning towards a later, more complicated envelope definition.
Your mistake is that each composite template can optionally contain only one document. The field name is document, not documents.
Instead of
"documents": {
"documentId": "1",
"name": "application_form.pdf",
"transformPdfFields": "true",
"documentBase64": "{{}}"
}
use
"document": {
"documentId": "1",
"name": "application_form.pdf",
"transformPdfFields": "true",
"documentBase64": "{{}}"
}
Also, I don't believe there's a need for the recipients outside of the composite templates structure. I'm not 100% sure about this issue though.
I was trying to use these two templates as a composite template thru the REST api. I sent out each template on its own and it worked fine. Here is the request from the log file:
Content-Length: 1526
Host: demo.docusign.net
X-DocuSign-Authentication: {"Username":"Kathleen.Jones#XXX.com","Password":"[omitted]","IntegratorKey":"[omitted]"}
X-Forwarded-For: 63.118.233.100, 104.129.194.117
{
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence": "1",
"templateId": "2d743750-f910-4a30-ad34-ac5bc0ca8daa"
},
{
"sequence": "2",
"templateId": "63479d79-a776-4767-a2a3-1ebd01d7d8fa "
}
],
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"name": "Joe Blow",
"email": "JoeBlow#outlook.com",
"recipientId": "1",
"roleName": "CEO"
},
{
"name": "Kathy Blow",
"email": "KathyBlow#outlook.com",
"recipientId": "2",
"roleName": "Uber CEO"
}
]
}
},
{
"sequence": "2",
"recipients": {
"signers": [
{
"name": "Joe Blow",
"email": "JoeBloww#outlook.com",
"recipientId": "2",
"roleName": "Uber CEO"
},
{
"name": "Kathy Blow",
"email": "KathyBlow#outlook.com",
"recipientId": "1",
"roleName": "CEO"
}
]
}
}
]
}
],
"status": "sent",
"emailSubject": "Please Sign the enclosed docs at your earliest convenience"
}
400 BadRequest
Content-Type: application/json; charset=utf-8
X-DocuSign-TraceToken: cb23f0ed-6be2-4189-9237-5575671f8f4b
{
"errorCode": "TAB_REFERS_TO_MISSING_DOCUMENT",
"message": "The DocumentId specified in the tab element does not refer to a document in this envelope. Tab refers to DocumentId 15100956 which is not present."
}
Like I said, I used the 2 templates standalone and they went out fine. Any ideas?
I found the answer right here in a StackOverflow answer:
In the request JSON you posted, you're specifying "documents" (plural) as a collection/array of document objects -- which isn't correct. Each Composite Template item within the compositeTemplates array can only contain, at most, a single document.
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.
Inline Template - Docs
Server Template
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--
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"
}
]
}
}