Pro tips for working with composite templates, Part III

In Part II of this blog series, I showed you how to override a document in a template while still using its tabs. In this post, I'm  going to talk about reusing templates for different recipients in the same envelope. How can you have two recipients sign their own separate instances of your reference template?

The answer for that scenario is to use composite templates. Imagine you have set up a template with a “Seller” role that defines where the tabs should be placed in a document, identical to the had setup in Part II. You can use this template in individual composites and scope the tabs to the recipients in each composite. For example:

{
  "emailSubject": "Document-scoped anchors with template",
  "status": "sent",
  "compositeTemplates": [
     {
   "compositeTemplateId": "1",
     "document" :
       {
         "documentId" : "1",
           "name": "Doc1",
           "documentBase64": "Doc1 Base64"
       },
        "inlineTemplates": [
           {
              "recipients": {
                 "signers": [
                    {
                       "email": "john@hiscompany.com",
                       "name": "John Smith",
                       "recipientId": "1",
                       "roleName": "Seller"
                    }
                 ]
              },
              "sequence": "2"
           }
        ],
        "serverTemplates": [
           {
              "sequence": "1",
              "templateId": "867a37ef-xxxx-xxxx-xxxx-1a3619ada310"
           }
        ]
     },
     {
   "compositeTemplateId": "2",
     "document" :
       {
         "documentId" : "1",
         "documentBase64": "Doc2 Base64",
         "name": "Doc2"
       },
        "inlineTemplates": [
           {
              "recipients": {
                 "signers": [
                    {
                       "email": "joe@hiscompany.com",
                       "name": "Joe Bar",
                       "recipientId": "1",
                       "roleName": "Seller"
                    }
                 ]
              },
              "sequence": "2"
           }
        ],
        "serverTemplates": [
           {
              "sequence": "1",
              "templateId": "867a37ef-xxxx-xxxx-xxxx-1a3619ada310"
           }
        ]
     }
  ]
}

Three important points:

  1. Notice the sequence numbers for each composite. The serverTemplate gets sequence = 1 and its document is replaced with the one you provide. The inlineTemplates where you specify the signers get the second sequence number. 
  2. Notice how both composites are referencing the same template ID. This is because you want to use the same tabs layout as defined in the template. Since the tabs are document-scoped, one will not affect the other.
  3. Notice how all the signers have the role “Seller”, which is the same role that was created in the serverTemplate (where you define where each tab must be placed.)

Thank you for reading this article. I hope you are starting to see how powerful composite templates can be!

Additional resources

Nima Poulad
Author
Nima Poulad
Senior Developer Advocate
Published
Related Topics