Using Docusign REST API to attach document to SignerAttachmentTab
<p>We have defined a template that will be filled in and signed by our customers. In this template we have some fields that we pre-populate along with some documents that we will attach. The customer will fill in other fields and attach more documents. We are using the REST API to generate the sign request. We are able to generate the correct REST request to fill the tabs in the template, set the recipients and successfully send the signature request.  All this works great. But now we're trying to get a document attached to the appropriate SignerAttachmentTab in the template and we cannot get REST to accept it.</p>

<p>We've tried using the Documents field but that doesn't work with templates it seems. We created a composite template and then defined a document for the document, server template for the template itself and an inline template to contain the tab data we want to populate. This keeps generating errors about the tab page number not being right. We've tried different values and we've looked over all the forum posts and documentation related to attaching documents to templates and none of them seem to work.</p>

<p>For the document we specify the file to upload, set the document ID and name. In the server template we specify the template ID. In the inline template we create a recipient, set their information, build up the envelope tabs with the data and then add a SignerAttachmentTab for the document. In this tab we set the document ID to match the document ID from the Document element. We set the tabLabel to the label used in the template itself. We've tried setting pagenumber but that doesn't change anything. All we want is for the document to be sent to the customer. When the open it they can double click the attachment field and view the document we're trying to send. </p>

<p>I'm trying to use the recipe explorer to get this to work using raw REST and it keeps failing with the TAB_PAGENUMBER_IS_NOT_IN_DOCUMENT error. It seems like the document is taking precedence over the template. Unfortunately I cannot change the order of the templates in the editor other than setting the sequence # on the server and inline templates. Here's the request that is generated using DocuSign's test system.</p>

<pre><code>{ 
    "compositeTemplates":[{
       "document":   {
           "documentBase64":"&lt;Base64BytesHere&gt;",
           "documentId":"2",
           "name":"Test.pdf"
       },
       "inlineTemplates":[{
           "recipients":{
               "signers":[{
                     "email":"abc@def.org",
                     "name":"Person",
                     "recipientId":"1",
                     "roleName":"Sender 1",
                     "tabs":{
                          "signerAttachmentTabs":[{
                               "documentId":"2",
                               "tabLabel":"MyAttachment"
                          }],
                          "textTabs":[{
                               "tabLabel":"someText",
                               "value":"Value1" }
                          ]}
                 }]},
             "sequence":"2"
         }],
         "serverTemplates":[{
               "sequence":"1",
               "templateId":"guid}]
             }],
         "emailBlurb":"A message",
         "emailSubject":"Test",
         "status":"sent"
}
</code></pre>

<p>I've looked at the existing posts in the forums and either they don't work for my case or they aren't trying to actually attach the documents to the template but simply include them as a document in addition to the template. </p>