Search code examples
docusignapidocusigncompositetmplts

Reorganize order of documents in a template using REST APIs


In docusign interface, there is an option to change the order of the documents in a template. Is it possible to re-order the documents in a template using REST APIs?

I have a requirement where end-user should be able to a) select the templates b) re-order the documents in selected templates c) Application should form envelope using selected templates and send it.

Both (a) and (c) features are working fine using REST APIs but when it comes to re-ordering the documents within the template, I am unable to find a solution.

This is the JSON request I am using for composite templates:

{"serverTemplates": [
    {
        "sequence": "1",
        "templateId": "'.$template_id.'"
     }
    ],
   "inlineTemplates": [
    {
      "sequence": "2",
       "recipients": {
            "signers": [
                   {
                     "email": "'.$emp_rec['email_id'].'",
                     "name": "'.$emp_rec['name'].'",
                     "recipientId": "1",
                     "roleName": "Employee",
                     "routingOrder": "1"
                   }
                 ]
       }
     }
  ]
}

Let me know if any more information required.


Solution

  • The order of documents appearing in an envelope is based on the order used when creating the envelope. The only exception to this is if building a draft envelope and using the PUT .../envelopes api call to add documents to the draft. This method supports the use of "order". Therefore, if creating an envelope via composite templates, the order of documents in the envelope is based on the order of the composites.

    For Composite Template envelope construction, you should think of each composite as a "unit of document contribution". In your snippet of a single composite, the lowest numbered sequence is the server template, so it will contribute the document(s) from the server template. All other referenced templates will be "applied" to that document.

    It isn't clear from your question whether you want to add documents from server templates or if you are saying that the particular server template has 2 or more documents in the template. If the latter, I strongly recommend breaking them apart into their own individual templates. This will give you maximum flexibility. Since a multi-document server template can't really be applied to a contributed document, I view them as only useful when creating an envelope from that single template.