Last active
March 22, 2016 17:35
-
-
Save Ergin008/11fa12fd98e1ca18baab to your computer and use it in GitHub Desktop.
code snippet that shows how to create an envelope with an embedded recipient using the DocuSign Node Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createAndSendEnvelopeWithEmbeddedRecipient (loginAccounts, next) { | |
var fileBytes = null; | |
try { | |
var fs = require('fs'), | |
path = require('path'); | |
// read file from a local directory | |
fileBytes = fs.readFileSync(path.resolve(__filename + '/..' + SignTest1File)); | |
} catch (ex) { | |
// handle error | |
console.log("Exception: " + ex); | |
} | |
// create a new envelope object that we will manage the signature request through | |
var envDef = new docusign.EnvelopeDefinition(); | |
envDef.setEmailSubject("[DocuSign Node SDK] - Please sign this doc"); | |
// add a document to the envelope | |
var doc = new docusign.Document(); | |
var base64Doc = new Buffer(fileBytes).toString('base64'); | |
doc.setDocumentBase64(base64Doc); | |
doc.setName("TestFile.pdf"); | |
doc.setDocumentId("1"); | |
var docs = []; | |
docs.push(doc); | |
envDef.setDocuments(docs); | |
// Add an embedded recipient to sign the document | |
var signer = new docusign.Signer(); | |
signer.setName("[RECIPIENT_NAME]"); | |
signer.setEmail("[RECIPIENT_EMAIL]"); | |
signer.setRecipientId("1"); | |
signer.setClientUserId("1234"); // must set clientUserId to embed the recipient! | |
// create a signHere tab somewhere on the document for the signer to sign | |
// default unit of measurement is pixels, can be mms, cms, inches also | |
var signHere = new docusign.SignHere(); | |
signHere.setDocumentId("1"); | |
signHere.setPageNumber("1"); | |
signHere.setRecipientId("1"); | |
signHere.setXPosition("100"); | |
signHere.setYPosition("100"); | |
// can have multiple tabs, so need to add to envelope as a single element list | |
var signHereTabs = []; | |
signHereTabs.push(signHere); | |
var tabs = new docusign.Tabs(); | |
tabs.setSignHereTabs(signHereTabs); | |
signer.setTabs(tabs); | |
// configure the envelope's recipient(s) | |
envDef.setRecipients(new docusign.Recipients()); | |
envDef.getRecipients().setSigners([]); | |
envDef.getRecipients().getSigners().push(signer); | |
// set envelope status to "sent" so we can sign it. Otherwise it's placed in draft folder | |
envDef.setStatus("sent"); | |
var envelopesApi = new docusign.EnvelopesApi(); | |
envelopesApi.createEnvelope(loginAccounts[0].accountId, envDef, null, function(error, envelopeSummary, response) { | |
if (error) { | |
return next(error); | |
} | |
if (envelopeSummary) { | |
console.log("EnvelopeSummary: " + JSON.stringify(envelopeSummary)); | |
envelopeId = envelopeSummary.envelopeId; | |
next(null, envelopeId, loginAccounts); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment