Search code examples
docusignapidocusigncompositetmplts

DocuSign Rest API to replace single template document


I would like to know how to replace a document with composite templates. The template has three documents and defines signer info. Even though I tried to replace only 1st document that fields (tags) are defined as below it doesn’t work well. If sequence number of inlineTemplates is 1 and its number of serverTemplates is 2, 1st document is replaced as expected but the remaining two documents are gone. If each sequence number changes to opposite, three documents defined in the template are remained in envelope and new document is not replaced to 1st document.

As long as I look for info across stackoverview and other sites I didn’t find any solution yet.

    {
    "compositeTemplates" : [
    {
                "serverTemplates": [
                    {
                        "sequence": "2",
                        "templateId": "cba8d3ae-3f0e-4329-9c7a-9da0e612f153"
                    }
                ],

                "inlineTemplates": [
                    {
                        "sequence": "1",
                        "documents": [  
                            {
                                "documentId": "1",
                                "name": "1Update.pdf",
                                "fileExtension" : "pdf",
                                "transformPdfFields" : "false",
                                "documentBase64":"<base64 content>

                            }
                            ],
                    }
                    ],


        }
        ],

        "status": "created"

}

Solution

  • If you server template has three documents and you want to replace first document with another one at the time creating an envelope then DocuSign will not be able to do as then DocuSign will expect that you are planning to replace all documents and it will throw an error and ask you to send other documents as well in the Inline Template.

    So solution for this scenario will be, you need to make multiple server template, at least in your case two server templates, one server template should have document which you want to replace and another server template which will be static and it will go as-is in the envelope. Once that is done then your composite templates will be an array of two composite template. First Composite template will have First Server Template and using InlineTemplate or by document node you can replace the server template document. And second composite template will have only documents coming from 2nd server templates, with the solution your code might look like below:

    In below code, document in server template d7697d56-e7ff-4a86-9b21-e98b81bd66c2 is getting replaced by Inline Template or you can pass it in document node also, and f30d22b7-17da-4b61-af00-5f418f7916ec is the server template where no documents need to be replaced, it will come as is from the server template.

    {
       "compositeTemplates": [
          {
             "compositeTemplateId":"1",
             "inlineTemplates": [
                {  
                   "documents":[
                            {
                              "documentBase64": "<PDFBytes>",
                              "documentId": "1",
                              "fileExtension": "pdf",
                              "name": "Runtime Agreement"
                     }
                   ],
                   "recipients": {
                      "signers": [
                         {
                            "email": "[email protected]",
                            "name": "John Doe",
                            "recipientId": "1",
                            "roleName": "Signer1",
                            "routingOrder": "1"
                         }
                      ]
                   },
                   "sequence": "1"
                }
             ],
             "serverTemplates": [
                {
                   "sequence": "2",
                   "templateId": "d7697d56-e7ff-4a86-9b21-e98b81bd66c2"
                }
             ]
          },
          {
             "compositeTemplateId":"2",
             "inlineTemplates": [
                {  
                   "recipients": {
                      "signers": [
                         {
                            "email": "[email protected]",
                            "name": "John Doe",
                            "recipientId": "1",
                            "roleName": "Signer1",
                            "routingOrder": "1"
                         }
                      ]
                   },
                   "sequence": "2"
                }
             ],
             "serverTemplates": [
                {
                   "sequence": "1",
                   "templateId": "f30d22b7-17da-4b61-af00-5f418f7916ec"
                }
             ]
          }
       ],
       "status": "sent"
    }