docusignapi

DocuSign: How do I dynamically replace placeholders in our source document?


We are attempting to use the DocuSign API for eSignatures on items such as leases & automatic billing authorizations. What I have are a set of .rtf documents provided to me by our legal team, and there are certain sections that need to be replaced dynamically. I have looked through the DocuSign REST API docs, and I think what we are supposed to be using are text tags. Ware using the PHP SDK. I have not set this document up as a template, as it would be great if we could just use a local file on the filesystem and then have placeholders automatically replaced by values specified in our payload.

What we would like to do is have fields in our documents (such as TenantName and TenantAddress) that we can assign values to, and have DocuSign dynamically replace these placeholders with the values we specify. I have tried doing this using Text Tabs, but the values are not being replaced. Here is a code sample:

$document = new Document([
    'document_base64' => $b64fc, // base64_encoded value of file_get_contents('path/to/document.pdf')
    'name' => 'Autobill Form',
    'file_extension' => 'pdf',
    'document_id' => '1',
]);

$tag1 = new Text();
$tag1->setTabLabel('TenantName');
$tag1->setValue('Joe Signer');
$tag1->setLocked(true);
$tag1->setDocumentId('1');
$tag1->setPageNumber('1');

$tag2 = new Text();
$tag2->setTabLabel('TenantAddress');
$tag2->setValue('123 Main St.');
$tag2->setLocked(true);
$tag2->setDocumentId('1');
$tag2->setPageNumber('1');

$tabs = new Tabs();
$tabs->setTextTabs([$tag1, $tag2]);

$document->setTabs($tabs);

// other code to set up recipients, envelopes, and get an embedded signing url

When I view the document, these fields are not replaced, and still have their placeholder values. I don't want to use anchors as I need the placeholder to be removed and replaced by DocuSign. I have also tried setting the text tabs on the Signer object, but that did not work either.

What am I doing wrong? This seems like it would be a fairly common use case for the DocuSign API, but I haven't been able to figure this out.


Solution

  • As Inbar states, the DocuSign eSignature API doesn't allow you to modify the underlying document. You'd need to external tooling to prepare the document prior to passing it into the API Call.

    That said, one possible option would be to have blank spaces in your document that align with Text tabs. If you pre-populate those tags and set them to be read-only, the placeholders tags will burn-in during the signing session. Spacing, alignment, and font likely won't be perfect, but with some adjustment you can do okay.