1

I'm using the DocuSign REST API to create an envelope from a template. My code works with single document templates or templates with multiple documents where only one document has tabs. If there are tabs on both documents I receive a 400 response with error code TAB_REFERS_TO_MISSING_DOCUMENT.

The response I receive is:

{
  "error": "invalid HTTP response",
  "message": {
    "errorCode": "TAB_REFERS_TO_MISSING_DOCUMENT",
    "message": "The DocumentId specified in the tab element does not refer to a document in this envelope. Tab refers to DocumentId 45159457 which is not present."
  },
  "status": 400,
  "url": "https://demo.docusign.net/restapi/v2/accounts/2826983/envelopes/"
}

My request is as follows:

{
  "status": "sent",
  "templateId": "bb283bfb-4049-431d-942a-9a485e4ebb41", 
  "emailSubject": "[[Signer UserName]], please sign this document",
  "documents": [
     {
       "documentId": "27069418",
       "documentBase64": "...",
       "name": "name.pdf"
     },
     {
       "documentId": "45159457",
       "documentBase64": "...",
       "name": "secondName.pdf"
     }
   ]
}

From what I've seen people receive this request when they submit invalid documentId's like 1 but the document that's "missing" is clearly attached. Am I missing something?


The final and working JSON request looks like so:

{
    "status": "sent",
    "emailSubject": "...",
    "compositeTemplates": [{
        "serverTemplates": [{
            "sequence": 2,
            "templateId": "..."
        }],
        "inlineTemplates": [{
            "sequence": 1,
            "documents": [{
                "documentId": "...",
                "name": "...",
                "documentBase64": "..."
            }, {
                "documentId": "...",
                "name": "...",
                "documentBase64": "..."
            }]
        }]
    }]
}
garfunkl3
  • 13
  • 4
  • Why are you including the `documents` property in your request? Are you trying to replace the documents in the template? – Praveen Reddy Jun 13 '17 at 19:21
  • Yes. I create a template, upload documents, and place tabs. Afterwards, when using a single document, sending this request makes an envelope with the new document and keeps the tabs from the template document – garfunkl3 Jun 13 '17 at 19:22
  • Do your new documents have the same number of pages as the original document? – Praveen Reddy Jun 13 '17 at 19:52
  • Yes, they're literally the same documents with some additional highlighting/text on them. – garfunkl3 Jun 13 '17 at 19:53
  • 1
    I believe composite templates are the only way you can accomplish your workflow, see CodingDawg's answer. – Ergin Jun 13 '17 at 22:46

2 Answers2

2

You can overcome the error using composite Templates. Specifying the new documents in an inlineTemplate with lower sequence number("sequence": "1") will ensure the inlineTemplate documents will replace the server template documents.

Here is a sample CreateEnvelope request.

{
    "emailSubject": "[[Signer UserName]], please sign this document",
    "status": "sent",
    "compositeTemplates": [
        {
            "inlineTemplates": [
                {
                    "sequence": "1",
                    "documents": [
                        {
                            "documentId": "27069418",
                            "name": "name.pdf",
                            "documentBase64": ""
                        },
                        {
                            "documentId": "45159457",
                            "name": "secondName.pdf",
                            "documentBase64": ""
                        }
                    ]
                }
            ],
            "serverTemplates": [
                {
                    "sequence": "2",
                    "templateId": "bb283bfb-4049-431d-942a-9a485e4ebb41"
                }
            ]
        }
    ]
}
Praveen Reddy
  • 7,295
  • 2
  • 21
  • 43
  • Firstly, thanks for your help. This results in an `"ENVELOPE_IS_INCOMPLETE"` error but it got me started in the right direction. Since I wanted to respect the signing order and tabs set in the template my request is as follows: `{status: sent, emailSubject: "", compositeTemplates: [{serverTemplates: [{sequence: 1, templateId: ...}], inlineTemplates: [{sequence: 1, documents:[...]}]}` – garfunkl3 Jun 14 '17 at 13:18
  • @garfunkl3 did you ever get past the ENVELOPE_IS_INCOMPLETE issue? – Developer Jun 13 '22 at 07:29
0

To replace the document(s) in a template you must use composite templates instructions in your Envelopes: create call.

In your use case, you want to composite together the template and then a new document "in front" of the existing document in the template.

"Compositing templates" is like compositing together multiple pieces of film to produce a final print.

Larry K
  • 47,808
  • 15
  • 87
  • 140