Two Templates in One Envelope with DocuSign API - docusignapi

I've been able to successfully start an envelope with a template using the templateID, but I'm attempting to generate an envelope with two documents inside that both have templates. In the DocuSign website interface it's possible to start a new envelope then "check off" multiple templates to add to the envelope.
I've found the API calls to:
Start an envelope with a template
Get a template
Add a document to an envelope
However, there's unfortunately nothing that I can find to add a template to a draft envelope once it's been created. The question here, in case it's not obvious, is: what is the API call to generate a new document from a template and add it to a pre-existing envelope in created status?

You can create an envelope based on multiple templates. The trick is to use the compositeTemplates optional property of the request.
Back in April 2013 I hosted a webinar focused on templates where I demonstrated 3 different template examples. They were increasing in complexity leading up to the third, where that last one shows how to combine multiple templates into one envelope. Here is the Gist for it, which contains PHP code and sample JSON bodies:
https://github.com/Ergin008/DocuSign-REST-API-Webinar-April2013
Here is the JSON for the third example, you'll want to add something similar to your request body:
{
"emailSubject": "DocuSign Templates Webinar - Example 3",
"emailBlurb": "Example #3 - Composite Templates",
"status": "sent",
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence": "1",
"templateId": "55A80182-2E9F-435D-9B16-FD1E1C0F9D74"
}
],
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"email": "test#docusign.com",
"name": "First Recipient",
"recipientId": "1",
"roleName": "RoleOne"
}
]
}
}
]
},
{
"serverTemplates": [
{
"sequence": "2",
"templateId": "44D9E888-3D86-4186-8EE9-7071BC87A0DA"
}
],
"inlineTemplates": [
{
"sequence": "2",
"recipients": {
"signers": [
{
"email": "test2#docusign.com",
"name": "Recipient 2",
"recipientId": "1",
"roleName": "RoleOne"
}
]
}
}
]
}
]
}
Note that the sequence property of the server template can be used to change the order that the template documents show up in the envelope.

To add to Ergin's answer.
You can add a template to an existing envelope using the applyEnvelopeTemplates api.
You can add templates to a document in the specified envelope using the EnvelopeTemplate:applyToDocuments api

Related

DocuSign API: Assign a delivery method to a TemplateRole to send SMS to a signer

I'm trying to make it so that specific signers to a document can be sent an envelope via SMS instead of email. I am using server templates to create the envelopes, but the examples don't seem to agree on whether to use a TemplateRole or use a Signer to create the envelope. So far I've been using TemplateRole, but it does not seem like there is a delivery method option (for only SMS).
In looking for answers I found a small reference to a bug "TT-3902" that was referenced two years ago and also on a post to the Java SDK, but at the same time another post from a year ago says it is possible - but the link to the API Explorer shows only using a Signer object, not a TemplateRole object...
Questions: Can I use the TemplateRole this way but haven't found the right example? Is there a workaround? Has bug TT-3902 been fixed? Do I need to recode my entire Envelope creation process to be different just to use the Signer objects instead?
Current Code (using Python SDK):
signer = TemplateRole(
role_name=signer_provided["role_name"],
name=signer_provided["name"],
email=signer_provided["email"],
tabs=tabs,
)
What I want to program for SMS delivery:
phone_number = RecipientPhoneNumber(country_code="1", number=signer_provided["phone_number"])
signer = TemplateRole(
delivery_method="SMS",
role_name=signer_provided["role_name"],
name=signer_provided["name"],
phone_number=phone_number,
tabs=tabs,
)
I also tried:
phone_number = RecipientPhoneNumber(country_code="1", number=signer_provided.get("phone_number"))
additional_notification = RecipientAdditionalNotification(secondary_delivery_method="SMS", phone_number=phone_number)
signer = TemplateRole(
additional_notification=additional_notification,
role_name=signer_provided["role_name"],
name=signer_provided["name"],
email=signer_provided["email"],
tabs=tabs,
)
But this only sent an email (using my developer account) and not an SMS at all. I would like it to only send via SMS in this case.
You will need to use Composite Templates for this to work
Here is what the JSON looks like:
{
"envelopeDefinition": {
"status": "sent",
"compositeTemplates": [
{
"compositeTemplateId": "1",
"serverTemplates": [
{
"sequence": "1",
"templateId": "1b66677c-xxxx-xxxx-xxxx-655a7c3890d9"
}
],
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"name": "Signer Name",
"roleName": "signer",
"deliveryMethod": "SMS",
"recipientId": "1",
"phoneNumber": {
"countryCode": "",
"number": ""
},
"tabs": {
"textTabs": [
{
"tabLabel": "signer_title",
"value": "Manager"
}
]
}
}
]
}
}
]
}
]
},
"envelopesCreateQP": {}
}

DocuSign API Composite Template Server Templates Understanding

After reading (here and here) and trying out composite templates, I'm not quite sure I understand how to properly use the Server Templates within the API request. The documentation mentions If supplied they are overlaid into the envelope in the order of their Sequence value so I've interpreted this as they would be merged together as one document. It seems they are merged together but it is yielding a result that I would not expect. The first one in the sequence is what is shown and you cannot see the others.
What I'd like to do is have a couple common headers that contain our different logos and combine that with whatever template I'm sending out. We cannot use the branding approach because they want it as part of the document within the template and as far as I can tell, there is no way to make that happen with branding.
Below is my (scrubbed) request. See my comments.
{
"brandId": "{{brandId}}",
"emailSubject": "Testing Subject",
"status": "SENT",
"compositeTemplates": [{
"serverTemplates": [{ // First document
"sequence": "1",
"templateId": "{{headerTemplateId}}" //Header logo template
}, {
"sequence": "2",
"templateId": "{{document1TemplateId}}" // Template with content
}
],
"inlineTemplates": [{
"sequence": "1",
"recipients": {
"signers": [{
"email": "test#test.com",
"name": "Leeroy Jenkins",
"roleName": "Customer",
"recipientId": "1"
}
]
}
}
]
}, {
"serverTemplates": [{ // Second document
"sequence": "2",
"templateId": "{{document2TemplateId}}"
}
],
"inlineTemplates": [{
"sequence": "2",
"recipients": {
"signers": [{
"email": "test#test.com",
"name": "Leeroy Jenkins",
"roleName": "Customer",
"recipientId": "1",
"tabs": {
"textTabs": [{
"tabLabel": "Address",
"value": "123 Test Rd "
}, {
"tabLabel": "CityStateZip",
"value": "Test/XY/12345"
}
]
}
}
]
}
}
]
}
]
}
As #Drew says, your immediate issue is that each individual composite template can only include zero or one server template.
Re: How to properly use the Server Templates within a composite template
Each composite template composites together different aspects of an envelope:
Zero or one template definitions stored on docusign.com
Newly defined recipients, tabs, documents, etc.
For example, composite templates can be used to create an envelope that includes document "B" instead of using the document included in a template on docusign.com.
Changing logos in documents
Unfortunately, the DocuSign compositing feature does not include a feature for combining the images from one document with another document to create a new (combined) document.
Some ideas:
If only page one of the contract includes the logo, then you could have multiple versions of page one (treating each as a separate document), and combine the logoed page one with the other pages to form a complete envelope.
Note that a document can be as short as a page. Recipients will view all of the envelope's documents together.
Use a PDF library to manipulate the PDF document itself to change the logo. There are now many PDF libraries available, with APIs for many languages and operating systems.
Use a SAAS PDF rendering service to combine the images with the content to obtain the final PDF. Eg, webmerge
Send DocuSign the document in a non-PDF format. For example, you can send a .docx document. If you're using the Windows stack, it may be easier for your application to create a custom logo version of a Word doc than a PDF.

DocuSign Status Code TAB_REFERS_TO_DOCUMENT_NO_TABS_ALLOWED?

I am currently using the REST api to create an envelope containing a document and a template which I have already set up in Docusign. I get the following error on the web request and can't find this error on the status code/error list provided by DocuSign to try debug the issue. Their support person suggests I ask here..
TAB_REFERS_TO_DOCUMENT_NO_TABS_ALLOWED -- The Tab refers to a document that does not allow tabs.
Has anyone experienced this?
Edit:
The issue appears to be related to the document section.
{
"emailBlurb":"Test Email Body",
"emailSubject": "Test Email Subject",
"status" : "sent",
"compositeTemplates": [
{
"serverTemplates": [
{
"sequence" : 1,
"templateId": "b1eccee3-9c00-4cb2-8d30-0400d51dcfe0"
}],
"inlineTemplates": [
{
"sequence" : 2,
"recipients": {
"signers" : [{
"email": "usera#bah.com",
"name": "usera",
"recipientId": "1",
"roleName": "Producer"
}]
}
}],
"document": {
"documentId": 1,
"name": "Test.docx",
"documentBase64":"[bytesremoved]",
"fileExtension":"docx"
}
}]
}
So you have a template on the server, with a document as part of the template?
But you want the envelope to use a different document with the template, yes?
It is my understanding that the documentId in the document section of the composite template must match the documentId used in the template if you want the document to be substituted for the template's document.
So check the definition of the template. Did you create the template programmatically or did you use the web browser DocuSign app? If the latter, then note that the first document in a template is not always given an id of 1.

Docusign signing url - Showing document 1 of a composite template

Using the docusign rest api i would like to create an envelope with 2 documents.
I will then be using the Post Recipient view to show document 1 to the first recipient (in an iframe) and once signed show document 2 in the same envelope to another recipients.
i have created the templates with different tempalteRoles (different names, order 5 and 10).
Its my understanding using a userId and the right settings in my docusign account, i can show document 1 to recipient 1 and then document 2 to recipient 2.
When i try and create the composite envelope the whole document is shown.
when i call the recipient status for the envelope it only shows one signer.
I have found the envelope will only create when the 2 template roles have the same clientUserId, userName and email, otherwise i get the error "ONESIGNALLSIGN_NOT_SATISFIED"
here is the envelope i am sending through
{
"accountId": "ACCOUNT_ID",
"emailSubject": "Email subject",
"status": "sent",
"templateId": "TEMPLATE_ID",
"templateRoles": [
{
"roleName": "PDS Customer",
"email": "pds#example.com",
"name": "TestFirstName TestSurname",
"clientUserId": "1",
"tabs": {
"textTabs": [
{
"tabLabel": "DocumentNumber",
"value": "123456789",
"locked": true,
"documentId": 1,
"pageNumber": 1
}
...removed some
]
}
},
{
"roleName": "Customer",
"email": "test#example.com",
"name": "mrTestFirstName TestSurname",
"clientUserId": "2",
"tabs": {
"textTabs": [
{
"tabLabel": "StorerEmail_LocalPart",
"value": "test",
"locked": true,
"documentId": 2,
"pageNumber": 1
}
...removed some
]
}
}
],
"compositeTemplates": [
{
"compositeTemplateId": 1,
"serverTemplates": [
{
"sequence": 1,
"templateId": "TEMPLATE_ID_2"
}
]
}
]
}
The error message is due to having Document Visibility enabled. In that scenario, each signer must have at least one tab present. Your second signer (embedded or not) must have at least one tab. In this case it'd probably be on the second document.
Your API call above does refer to a second documentId though so you may be okay there.
I would suggest that you not mix the "simple" sending (using templateRoles at the top level) with composite templates. Instead, add an inline template to the compositeTemplates structure with all of your recipient information. You may be seeing some odd behavior due to mixing those.
Lastly, the default Document Visibility configuration will show a document to a recipient only if they have a tab on that document. If your second signer should see all documents then you must either add a tab for them on each document or explicitly set visibility per document.

Not able to pass in values to docusign template

I'm trying to figure out how to pass in form field values to my docusign template. I looked at the v2 API docs but found nothing.
You just specify in your JSON request properties (or XML) by using the tabLabel and value properties. For instance, this would populate 2 data fields, one named "ApplicantName" the second "ApplicantSSN"...
{
"accountId": "221765",
"emailSubject": "DocuSign Templates Webinar - Example 2",
"emailBlurb": "Example #2 - Dynamically Populate Form Fields",
"templateId": "44D9E888-3D86-4186-8EE9-7071BC87A0DA",
"templateRoles": [
{
"email": "jondow#email.com",
"name": "Jon Dow",
"roleName": "RoleOne",
"tabs": {
"textTabs": [
{
"tabLabel": "ApplicantName",
"value": "John Doe"
},
{
"tabLabel": "ApplicantSSN",
"value": "12-345-6789"
}
]
}
}
],
"status": "sent"
}
For a full code walkthrough you can combine the above JSON with one of the sample code walkthroughs here:
DocuSign API Walkthrough #1

Resources