DocuSign Rest API to replace single template docum

2019-08-22 11:43发布

问题:

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"

}

回答1:

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@gmail.com",
                        "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@gmail.com",
                        "name": "John Doe",
                        "recipientId": "1",
                        "roleName": "Signer1",
                        "routingOrder": "1"
                     }
                  ]
               },
               "sequence": "2"
            }
         ],
         "serverTemplates": [
            {
               "sequence": "1",
               "templateId": "f30d22b7-17da-4b61-af00-5f418f7916ec"
            }
         ]
      }
   ],
   "status": "sent"
}


回答2:

You need to use the document node of the composite template, which is Sequence "0" by default, thus it uses the document pdf bytes vs the Server Template or inline documents pdf bytes.

"compositeTemplates": [{
"serverTemplates": [{
"inlineTemplates": [{
"document": ....

Here is part of what you need to understand about Sequence numbers and physical order - In composite templates, physical order overrules the "index/sequence" per composite template node.

The "sequence" index is the internal referential glue, but not really the row order in the in-memory model.

The lower the sequence: document node (not documents) between server, inline and document being 0 is how the "PDF/DOC bytes are determined, and the higher the sequence number the feature that wins aka doc vis in one template, vs another or the notification days number.

Also, remember status "created" means you do all the clean up on needed roles, tags, etc, vs "sent" means DocuSign will remove any incomplete tags, swap documents, etc. So it may not generally show you the final result until you issue "sent".

Remember you can add a "Blocking (advanced concept)" recipient so you can "view" the result post "sent" before it goes to the client. Just us an "undeliverable" email address that will do a bounce back, then issue a sender view to see the result, then "lock/correct/unlock" envelope, removing "blocking" user if you need to validate in a real production scenario.