Create envelope
Embedded signing ceremony
carbon copy
certified delivery
Composite Templates
document
signer
Tabs
A-Z complete index
Status
API Request Builder
Set the email and name fields of the signer and Embedded Signing Ceremony blocks.
Then click the Send Envelope button (top right).
Node.JS SDK
download frameworkdownload example#!/usr/bin/env node// DocuSign API Request Builder example. Generated: Wed, 27 Nov 2024 19:21:37 GMT// DocuSign Ⓒ 2024. MIT License -- https://opensource.org/licenses/MIT'use strict';const fse = require('fs-extra'), path = require('path'), docusign = require('docusign-esign'), baseUri = 'https://demo.docusign.net/'// Note: the accessToken is for testing and is temporary. It is only good for 8 hours from the time you// authenticated with API Request Builder. In production, use an OAuth flow to obtain access tokens., accessToken = '', accountId = '', documentDirectory = '.'; // The directory with your documents// Send the envelopeasync function sendDocuSignEnvelope () {let signHereTab1 = docusign.SignHere.constructFromObject({anchorString: "/sig1/",anchorUnits: "pixels",anchorXOffset: "20"});let signHereTabs1 = [signHereTab1];let tabs1 = docusign.Tabs.constructFromObject({signHereTabs: signHereTabs1});let signer1 = docusign.Signer.constructFromObject({clientUserId: "1000",email: "signer_email@example.com",name: "Signer's name",recipientId: "1",tabs: tabs1});let signers1 = [signer1];let recipients1 = docusign.Recipients.constructFromObject({signers: signers1});let document1 = docusign.Document.constructFromObject({documentId: "1",fileExtension: "pdf",documentBase64: await readDocFileB64("anchorfields.pdf"), // filename is anchorfields.pdfname: "Example document"});let documents1 = [document1];let envelopeDefinition = docusign.EnvelopeDefinition.constructFromObject({documents: documents1,emailSubject: "Please sign the attached document",recipients: recipients1,status: "sent"});try {const dsApi = new docusign.ApiClient();dsApi.addDefaultHeader('Authorization', 'Bearer ' + accessToken);dsApi.setBasePath(baseUri + 'restapi');const envelopesApi = new docusign.EnvelopesApi(dsApi);const envResults = await envelopesApi.createEnvelope(accountId,{envelopeDefinition: envelopeDefinition});console.log (`Create envelope results: ${JSON.stringify(envResults, null, ' ')}`);console.log (`The envelopeId is ${envResults.envelopeId}`);return envResults.envelopeId;} catch (e) {console.log (`Error from DocuSign create envelope: ` +`${(e && e.response && JSON.stringify(e.response.body))||e}`);return false}}/*** Create the recipient view URL* NOTE: the URL is time limited and must be used within a couple of minutes*/async function recipientView (envelopeId) {let recipientViewRequest = docusign.RecipientViewRequest.constructFromObject({authenticationMethod: "None",clientUserId: "1000",email: "signer_email@example.com",returnUrl: "https://docusign.com",userName: "Signer's name"});if (!recipientViewRequest || !envelopeId) {return}try {const dsApi = new docusign.ApiClient()dsApi.addDefaultHeader('Authorization', 'Bearer ' + accessToken);dsApi.setBasePath(baseUri + 'restapi');const envelopesApi = new docusign.EnvelopesApi(dsApi);const viewResults = await envelopesApi.createRecipientView(accountId, envelopeId,{recipientViewRequest: recipientViewRequest});console.log (`\nCreate recipient view succeeded.`);console.log (`Open the signing ceremony's long URL within 5 minutes: \n${viewResults.url}\n\n`);} catch (e) {console.log (`Error from DocuSign create recipient view: ` +`${(e && e.response && JSON.stringify(e.response.body))||e}`);}}/*** Return the file's contents, Base64 encoded.* @param {string} filename*/async function readDocFileB64 (filename) {const filePath = path.resolve(documentDirectory, filename);try {const contents = await fse.readFile(filePath);return Buffer.from(contents).toString('base64')} catch (e) {console.log (`Couldn't read ${filePath}: ${e}`); process.exit(1)}}// The mainline/*** The mainline can't use "await". So this intermediate function is used.*/async function asyncMainline() {let envelopeId;envelopeId = await sendDocuSignEnvelope();await recipientView (envelopeId);console.log("Done.\n");}asyncMainline()