I'm using the DocuSign REST API to create an envelope from a template. My code works with single document templates or templates with multiple documents where only one document has tabs. If there are tabs on both documents I receive a 400 response with error code TAB_REFERS_TO_MISSING_DOCUMENT.
The response I receive is:
{
"error": "invalid HTTP response",
"message": {
"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 45159457 which is not present."
},
"status": 400,
"url": "https://demo.docusign.net/restapi/v2/accounts/2826983/envelopes/"
}
My request is as follows:
{
"status": "sent",
"templateId": "bb283bfb-4049-431d-942a-9a485e4ebb41",
"emailSubject": "[[Signer UserName]], please sign this document",
"documents": [
{
"documentId": "27069418",
"documentBase64": "...",
"name": "name.pdf"
},
{
"documentId": "45159457",
"documentBase64": "...",
"name": "secondName.pdf"
}
]
}
From what I've seen people receive this request when they submit invalid documentId's like 1 but the document that's "missing" is clearly attached. Am I missing something?
The final and working JSON request looks like so:
{
"status": "sent",
"emailSubject": "...",
"compositeTemplates": [{
"serverTemplates": [{
"sequence": 2,
"templateId": "..."
}],
"inlineTemplates": [{
"sequence": 1,
"documents": [{
"documentId": "...",
"name": "...",
"documentBase64": "..."
}, {
"documentId": "...",
"name": "...",
"documentBase64": "..."
}]
}]
}]
}
You can overcome the error using composite Templates. Specifying the new documents in an inlineTemplate with lower sequence number("sequence": "1") will ensure the inlineTemplate documents will replace the server template documents.
Here is a sample CreateEnvelope request.
{
"emailSubject": "[[Signer UserName]], please sign this document",
"status": "sent",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence": "1",
"documents": [
{
"documentId": "27069418",
"name": "name.pdf",
"documentBase64": ""
},
{
"documentId": "45159457",
"name": "secondName.pdf",
"documentBase64": ""
}
]
}
],
"serverTemplates": [
{
"sequence": "2",
"templateId": "bb283bfb-4049-431d-942a-9a485e4ebb41"
}
]
}
]
}
To replace the document(s) in a template you must use composite templates instructions in your Envelopes: create call.
In your use case, you want to composite together the template and then a new document "in front" of the existing document in the template.
"Compositing templates" is like compositing together multiple pieces of film to produce a final print.
Related
I am able to send a POST request to send an existing template for signing. What I'm trying to do now is attach a PDF to the signature template. The attached PDF does not need to be signed / is not a template. It is just a PDF copy of a document as an appendix to the contract.
The request is going through ok, but I'm getting the error: "TAB_PAGENUMBER_IS_NOT_IN_DOCUMENT",\r\n "message": "The pagenumber specified in the tab element is not in the document that the tab refers to. Tab on Page 8 of Document 1 for Recipient 1"
JSON:
{
"emailSubject": "Please sign this document set",
"templateId": "xxxxxxx",
"templateRoles": [
{
"email": "email#example.com",
"roleName": "Buyer",
"name": "Buyer Name"
}
],
"documents": [
{
"signerMustAcknowledge": "no_interaction",
"order": "asc",
"name": "MyCompany Quote",
"includeInDownload": true,
"documentId": "2",
"documentBase64": "<base64string>",
"display": "inline"
},
],
"status": "sent"
}
How to attach a document to an online template?
The error you are seeing is because DocuSign will try to replace the document in the template with the file you are providing.
You should be able to add this additional document by using composite templates instead. https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-composite-template-embedded/
Here is a sample:
{
"compositeTemplates": [
{
"compositeTemplateId": "1",
"inlineTemplates": [
{
"recipients": {
"signers": [
{
"email": "email#example.com",
"roleName": "Buyer",
"name": "Buyer Name"
}
]
},
"sequence": "1"
}
],
"serverTemplates": [
{
"sequence": "1",
"templateId": "xxxxxxx"
}
]
},
{
"compositeTemplateId": "2",
"document": {
"documentBase64": "<base64string>",
"documentId": "2",
"fileExtension": "pdf",
"name": "MyCompany Quote"
},
"inlineTemplates": [
{
"sequence": "1"
}
]
}
],
"emailSubject": "Please sign this document set",
"status": "sent"
}
The first composite template is used to populate your existing template with the signers information. The second composite template is where you add the additional document you want your users to sign. You can also include additional tabs inside the inlineTemplates if they are needed in the future
I have created a template via the DocuSign UI; that template contains some tabs for various roles.
I want to send a document via DocuSign REST API, in which the template (only the tabs e.g. signHere, initiateHere, Title etc) will apply.
I haven't added any recipient on the template. What I want to use from that template are only the tabs.
My JSON
{
"emailBlurb":"Test Email Body",
"emailSubject": "Test Email Subject",
"status" : "sent",
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence" : 1,
"templateId": "c9e5adfa-d708-4467-a0ea-c615fa429a0f"
}],
"inlineTemplates": [
{
"sequence" : 2,
"recipients": {
"signers" : [{
"email": "nalam#relisource.com",
"name": "Noor",
"recipientId": "1",
"roleName": "Applicant"
}]
}
}],
"document": {
"documentId": 1,
"name": "test1.pdf",
"documentBase64":"Base64streamhere"
}
}]
}
It gives me the following error.
{
"errorCode": "INVALID_CONTENT_TYPE",
"message": "Content Type specified is not supported."
}
I am using POSTMAN. What is the problem here ?
Your documentBase64 attribute doesn't look right. Perhaps an error in copying it? Also, setting the fileExtension is highly recommended:
It should be
"document": {
...
"documentBase64": "Base64EncodedString",
"fileExtension": "pdf"
}
I suggest you use API request logging to see exactly what Postman is sending.
Template document substitution
If you're trying to substitute a document at runtime for the document in a server template, see the answers to this SO question for additional tips.
What you want here is the serverTemplate to be in sequence with the inlineTemplate so they need to have the same sequence number. Also you need another inline template to hold your document object. Something like this:
{
"emailBlurb":"Test Email Body",
"emailSubject": "Test Email Subject",
"status" : "sent",
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence" : 1,
"templateId": "c9e5adfa-d708-4467-a0ea-c615fa429a0f"
}],
"inlineTemplates": [
{
"sequence" : 1,
"recipients": {
"signers" : [{
"email": "nalam#relisource.com",
"name": "Noor",
"recipientId": "1",
"roleName": "Applicant"
}]
}
}],
"inlineTemplates": [
{
"sequence" : 2
"document": {
"documentId": 1,
"name": "test1.pdf",
"documentBase64":"Base64streamhere"
}
}
}]
}
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'm confused about the difference between "tabs" and "custom fields," perhaps --
When I send a json to DocuSign API's baseURL/envelopes, asking the API to send an envelope with a template, it works fine:
{ "accountId": "xxx",
"status": "sent",
"emailSubject": "Please sign this document",
"emailBlurb": "Here's a document for you to sign",
"templateId": "xxxx",
"templateRoles": [
{
"email": "test#email.com",
"name": "Test Person",
"roleName": "parent_signer" }] }
When I try to add parameters for custom field filling, I get a 400 error:
{ "accountId": "xxx",
"status": "sent",
"emailSubject": "Please sign this document",
"emailBlurb": "Here's a document for you to sign",
"templateId": "xxxx",
"templateRoles": [
{
"email": "test#email.com",
"name": "Test Person",
"tabs": [
{ "textTabs":
[
{"tabLabel": "Doc_Name",
"name": "Doc_Name",
"value": "Doc Name Data Would Go Here"}
]
}
],
"roleName": "parent_signer" }] }
And the single document in my template in question has custom fields with those names.
https://imgur.com/z519zm3
You need to specify the document and page in which the tab needs to be displayed.
In JSON, it would look like below :
"textTabs": [
{
"tabLabel": "Doc_Name",
"name": "Doc_Name",
"value": "Doc Name Data Would Go Here",
"DocumentId": "123",
"PageNumber": "1"
}
"tabs" is not an array. There is a docusign exmaple here:
https://developers.docusign.com/esign-rest-api/guides/features/templates
You're code should look like this:
...
"templateRoles": [ // is an array
{
"email": "test#email.com",
"name": "Test Person",
"tabs": { // is not an array (an object)
"textTabs": [ // is an array (of objects)
{
"tabLabel": "Doc_Name", // should match Template "Data Label"
"name": "Doc_Name", // this field is unnecessary
"value": "Doc Name Data Would Go Here"
}
] // , other arrays of tabs like checkboxTabs may go here as well
}
"roleName": "parent_signer" }] }
I am trying to use the docusign-node-client to send an envelope using the createEnvelope class. This class sends a REST API request to the /envelopes endpoint. The envelope I am trying to send contains a Composite Template.
Here is the body I am attempting to send to docusign
{
"emailSubject": "Sent from Node SDK",
"emailBlurb": "Email body here",
"customFields": {
"textCustomFields": [
{
"name": "DSFSSourceObjectId",
"required": false,
"show": false,
"value": "dealIdHere"
}
]
},
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence": "1",
"documents": [
{
"documentBase64": "base64StringHere",
"documentId": "1",
"fileExtension": ".pdf",
"name": "filename.pdf"
}
],
"envelope": {
"emailBlurb": "Email body here",
"emailSubject": "Sent from Node SDK",
"customFields": {
"textCustomFields": [
{
"name": "DSFSSourceObjectId",
"required": false,
"show": false,
"value": "dealIdHere"
}
]
},
"recipients": {
"signers": [
{
"email": "myEmail#domain.com",
"name": "My Name",
"recipientId": "1"
}
]
}
}
}
],
"serverTemplates": [
{
"sequence": "1"
}
]
}
],
"status": "sent"
}
When I send this body I get the following error: "The request contained at least one invalid parameter. Invalid value specified for \'templateId\' in composite template sequence: 1"
If I remove the serverTemplates array, I get this error: "The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line."
If I include a valid templateId in the serverTemplate object it creates an envelope successfully.
The as is application I am converting to Node JS used the Docusign SOAP API and is able to send composite templates with 1 to many documents. Each of these documents can be associated to their own document template or no docusign template.
Does docusign not accept composite templates without some sort of reference to a template id?
You are specifying the inlineTemplate.envelope property incorrectly. You can define the recipients and custom fields directly within the inlineTemplate. You do not have to specify the emailSubject/emailBlurb within the inlineTemplate.
Also note that the custom fields specified at the root level will be ignored when using composite templates. See this answer
The following json should work for you.
{
"emailSubject": "Sent from Node SDK",
"emailBlurb": "Email body here",
"status": "sent"
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence": "1",
"documents": [
{
"documentBase64": "base64StringHere",
"documentId": "1",
"fileExtension": ".pdf",
"name": "filename.pdf"
}
],
"customFields": {
"textCustomFields": [
{
"name": "DSFSSourceObjectId",
"required": false,
"show": false,
"value": "dealIdHere"
}
]
},
"recipients": {
"signers": [
{
"email": "myEmail#domain.com",
"name": "My Name",
"recipientId": "1"
}
]
}
}
]
}
]
}