we are attempting our first DocuSign API Project and have hit a snag. We're using PHP API for DocuSign, and we are attempting to create an envelope from a template that has static documents inside it, then add one other custom-generated document, then send the envelope. But we can't figure out how to make it work.
We originally tried creating the envelope, apply the template, then add the static document, then upload/sending the envelope, which only sends the template. Then, after research, tried creating the envelope, apply the template, upload the envelope, add the static document then sending, which only sent the static pages too.
Here's our current code we're using:
public function send($signer_name,$signer_email, $cc_name, $cc_email, $template_id,$email_subject, $extrapdf = null) {
$this->checkToken();
$sign_here = new \DocuSign\eSign\Model\SignHere([
'anchor_string' => '/sn1/', 'anchor_units' => 'pixels',
'anchor_y_offset' => '10', 'anchor_x_offset' => '20']);
//create roles for signers
$templateRole = new DocuSign\eSign\Model\TemplateRole();
$templateRole->setEmail($signer_email);
$templateRole->setName($signer_name);
$templateRole->setRoleName('Signer 1');
$templateRole->setTabs(new \DocuSign\eSign\Model\Tabs(['sign_here_tabs' => [$sign_here]]));
$templateRole2 = new DocuSign\eSign\Model\TemplateRole();
$templateRole2->setEmail($cc_email);
$templateRole2->setName($cc_name);
$templateRole2->setRoleName('Signer 2');
$templateRole2->setTabs(new \DocuSign\eSign\Model\Tabs(['sign_here_tabs' => [$sign_here]]));
//create envelope definition
$envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
//set template to be used on envelope
$envelop_definition->setTemplateId($template_id);
//set email subject on envelope
$envelop_definition->setEmailSubject($email_subject);
//apply template roles from above to envelope
$envelop_definition->setTemplateRoles(array($templateRole, $templateRole2));
//create new instance of envelope API
$envelopeApi = new DocuSign\eSign\Api\EnvelopesApi(self::$apiClient);
//go ahead and create the envelope at DocuSign
$results = $envelopeApi->createEnvelope(self::$accountID, $envelop_definition);
//get the created envelope Envelope ID
$envelopeId = $results['envelope_id'];
//create another envelope definition.
$envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
//see if we have an additional PDF to add to the envelope created above.
if ($extrapdf != null) {
//if so, base64 encode it.
$extrapdf64 = base64_encode($extrapdf);
//create a new document
$document = new DocuSign\eSign\Model\Document();
$document->setDocumentBase64($extrapdf64);
$document->setName("HomeownershipCounseling.pdf");
$document->setDocumentId("1");
$document->setFileExtension("PDF");
//attach document to envelope definition.
$envelop_definition->setDocuments([$document]);
//update the envelope definition to sent to get DocuSign to actually send the envelope.
$envelop_definition->setStatus('sent');
//apply changes to the original envelope above.
$results = $envelopeApi->update(self::$accountID, $envelopeId, $envelop_definition);
}
return $results;
}
The envelope does send, but it only sends the static document that was in the template. We're expecting the static document in the template AND the dynamically generated PDF to both be in the DocuSign Envelope.
Thanks!