Last active
February 20, 2018 03:24
-
-
Save DSDevCenter/8a769c1fb04f5d675fbc479595eb44a9 to your computer and use it in GitHub Desktop.
DocuSign NODE SDK Create Envelope with embedded recipient
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
// create a byte array that will hold our document bytes | |
var fileBytes = null; | |
try { | |
var fs = require('fs'); | |
var path = require('path'); | |
// read file from a local directory | |
fileBytes = fs.readFileSync(path.resolve(__dirname, "test.pdf")); | |
// fileBytes = fs.readFileSync(path.resolve(__dirname, "[PATH/TO/DOCUMENT]")); | |
} catch (ex) { | |
// handle error | |
console.log('Exception: ' + ex); | |
} | |
// create an envelope that will store the document(s), field(s), and recipient(s) | |
var envDef = new docusign.EnvelopeDefinition(); | |
envDef.emailSubject = 'Please sign this document sent from Node SDK'; | |
// add a document to the envelope | |
var doc = new docusign.Document(); | |
var base64Doc = new Buffer(fileBytes).toString('base64'); | |
doc.documentBase64 = base64Doc; | |
doc.name = 'TestFile.pdf'; // can be different from actual file name | |
doc.extension = 'pdf'; | |
doc.documentId = '1'; | |
var docs = []; | |
docs.push(doc); | |
envDef.documents = docs; | |
// add a recipient to sign the document, identified by name and email we used above | |
var signer = new docusign.Signer(); | |
signer.email = '{USER_EMAIL}'; | |
signer.name = '{USER_NAME}'; | |
signer.recipientId = '1'; | |
//*** important: must set the clientUserId property to embed the recipient! | |
// otherwise DocuSign platform will treat recipient as remote and your | |
// integration will not be able to generate a signing token for the recipient | |
signer.clientUserId = '1001'; | |
// create a signHere tab 100 pixels down and 150 right from the top left | |
// corner of first page of document | |
var signHere = new docusign.SignHere(); | |
signHere.documentId = '1'; | |
signHere.pageNumber = '1'; | |
signHere.recipientId = '1'; | |
signHere.xPosition = '100'; | |
signHere.yPosition = '150'; | |
// 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.signHereTabs = signHereTabs; | |
signer.tabs = tabs; | |
// add recipients (in this case a single signer) to the envelope | |
envDef.recipients = new docusign.Recipients(); | |
envDef.recipients.signers = []; | |
envDef.recipients.signers.push(signer); | |
// send the envelope by setting |status| to "sent". To save as a draft set to "created" | |
envDef.status = 'sent'; | |
// instantiate a new EnvelopesApi object | |
var envelopesApi = new docusign.EnvelopesApi(); | |
// call the createEnvelope() API to create and send the envelope | |
envelopesApi.createEnvelope(accountId, {'envelopeDefinition': envDef}, function (err, envelopeSummary, response) { | |
if (err) { | |
return next(err); | |
} | |
console.log('EnvelopeSummary: ' + JSON.stringify(envelopeSummary)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment