Skip to content

Commit a8a19ae

Browse files
Devdocs 5563 (#41)
update bulk send example
1 parent 9089515 commit a8a19ae

File tree

3 files changed

+186
-176
lines changed

3 files changed

+186
-176
lines changed

lib/eSignature/examples/bulkSendEnvelope.js

Lines changed: 170 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -4,174 +4,184 @@
44
* @author DocuSign
55
*/
66

7-
const fs = require("fs-extra");
8-
const docusign = require("docusign-esign");
7+
const fs = require("fs-extra");
8+
const docusign = require("docusign-esign");
99

10-
/**
11-
* This function does the work of creating the envelope
12-
*/
13-
const bulkSendEnvelopes = async (args) => {
14-
let docBytes = fs.readFileSync(args.docFile);
15-
let recipients = (list) => {
16-
return [
17-
{
18-
name: list.signer.name,
19-
email: list.signer.email,
20-
roleName: "signer",
21-
},
22-
{
23-
name: list.cc.name,
24-
email: list.cc.email,
25-
roleName: "CC",
26-
},
27-
];
28-
};
10+
/**
11+
* This function does the work of creating the envelope
12+
*/
13+
const bulkSendEnvelopes = async (args) => {
14+
let docBytes = fs.readFileSync(args.docFile);
15+
let recipients = (list) => {
16+
return [
17+
{
18+
name: list.signer.name,
19+
email: list.signer.email,
20+
roleName: "signer",
21+
},
22+
{
23+
name: list.cc.name,
24+
email: list.cc.email,
25+
roleName: "CC",
26+
},
27+
];
28+
};
2929

30-
// Step 1. Construct your API headers
31-
let dsApiClient = new docusign.ApiClient();
32-
dsApiClient.setBasePath(args.basePath);
33-
dsApiClient.addDefaultHeader("Authorization", "Bearer " + args.accessToken);
30+
// Construct your API headers
31+
// Step 2 start
32+
let dsApiClient = new docusign.ApiClient();
33+
dsApiClient.setBasePath(args.basePath);
34+
dsApiClient.addDefaultHeader("Authorization", "Bearer " + args.accessToken);
35+
// Step 2 end
3436

35-
let bulkEnvelopesApi = new docusign.BulkEnvelopesApi(dsApiClient);
36-
let envelopeApi = new docusign.EnvelopesApi(dsApiClient);
37+
let bulkEnvelopesApi = new docusign.BulkEnvelopesApi(dsApiClient);
38+
let envelopeApi = new docusign.EnvelopesApi(dsApiClient);
3739

38-
// Step 2. Create bulk list
39-
let bulkList = await bulkEnvelopesApi.createBulkSendList(args.accountId, {
40-
bulkSendingList: {
41-
name: "sample.csv",
42-
bulkCopies: [
43-
{
44-
recipients: recipients(args.list1),
45-
},
46-
{
47-
recipients: recipients(args.list2),
48-
},
49-
],
50-
},
51-
});
40+
// Create bulk list
41+
// Step 3 start
42+
let bulkList = await bulkEnvelopesApi.createBulkSendList(args.accountId, {
43+
bulkSendingList: {
44+
name: "sample.csv",
45+
bulkCopies: [
46+
{
47+
recipients: recipients(args.list1),
48+
},
49+
{
50+
recipients: recipients(args.list2),
51+
},
52+
],
53+
},
54+
});
55+
// Step 3 end
5256

53-
// Step 3. Create the draft envelope
54-
let envelope = await envelopeApi.createEnvelope(args.accountId, {
55-
envelopeDefinition: {
56-
envelopeIdStamping: "true",
57-
emailSubject: "Please sign",
58-
status: "Created",
59-
documents: [
60-
{
61-
documentBase64: Buffer.from(docBytes).toString("base64"),
62-
name: "lorem",
63-
fileExtension: "pdf",
64-
documentId: "2",
65-
},
66-
],
67-
recipients: {
68-
signers: [
69-
{
70-
name: "Multi Bulk Recipient::signer",
71-
email: "multiBulkRecipients-signer@docusign.com",
72-
roleName: "signer",
73-
routingOrder: "1",
74-
status: "created",
75-
deliveryMethod: "email",
76-
recipientId: "1",
77-
recipientType: "signer",
78-
tabs: docusign.Tabs.constructFromObject({
79-
signHereTabs: [docusign.SignHere.constructFromObject({
80-
anchorString: "/sn1/",
81-
anchorYOffset: "10",
82-
anchorUnits: "pixels",
83-
anchorXOffset: "20",
84-
})],
85-
})
86-
},
87-
{
88-
name: "Multi Bulk Recipient::cc",
89-
email: "multiBulkRecipients-cc@docusign.com",
90-
roleName: "cc",
91-
routingOrder: "1",
92-
status: "created",
93-
deliveryMethod: "email",
94-
recipientId: "2",
95-
recipientType: "cc",
96-
},
97-
],
98-
},
99-
},
100-
});
57+
// Create the draft envelope
58+
// Step 4 start
59+
let envelope = await envelopeApi.createEnvelope(args.accountId, {
60+
envelopeDefinition: {
61+
envelopeIdStamping: "true",
62+
emailSubject: "Please sign",
63+
status: "Created",
64+
documents: [
65+
{
66+
documentBase64: Buffer.from(docBytes).toString("base64"),
67+
name: "lorem",
68+
fileExtension: "pdf",
69+
documentId: "2",
70+
},
71+
],
72+
recipients: {
73+
signers: [
74+
{
75+
name: "Multi Bulk Recipient::signer",
76+
email: "multiBulkRecipients-signer@docusign.com",
77+
roleName: "signer",
78+
routingOrder: "1",
79+
status: "created",
80+
deliveryMethod: "email",
81+
recipientId: "1",
82+
recipientType: "signer",
83+
tabs: docusign.Tabs.constructFromObject({
84+
signHereTabs: [docusign.SignHere.constructFromObject({
85+
anchorString: "/sn1/",
86+
anchorYOffset: "10",
87+
anchorUnits: "pixels",
88+
anchorXOffset: "20",
89+
})],
90+
})
91+
},
92+
],
93+
carbonCopies: [
94+
{
95+
name: "Multi Bulk Recipient::cc",
96+
email: "multiBulkRecipients-cc@docusign.com",
97+
roleName: "cc",
98+
routingOrder: "1",
99+
status: "created",
100+
deliveryMethod: "email",
101+
recipientId: "2",
102+
recipientType: "cc",
103+
},
104+
],
105+
},
106+
},
107+
});
108+
// Step 4 end
101109

102-
// Step 4. Add an envelope custom field set to the value of your listId EnvelopeCustomFields::create)
103-
// This Custom Field is used for tracking your Bulk Send via the Envelopes::Get method
104-
await envelopeApi.createCustomFields(args.accountId, envelope.envelopeId, {
105-
customFields: {
106-
textCustomFields: [
107-
{
108-
name: "mailingListId",
109-
required: "false",
110-
show: "false",
111-
value: bulkList.listId,
112-
},
113-
],
114-
},
115-
});
110+
// Add an envelope custom field set to the value of your listId EnvelopeCustomFields::create)
111+
// This Custom Field is used for tracking your Bulk Send via the Envelopes::Get method
112+
// Step 5 start
113+
await envelopeApi.createCustomFields(args.accountId, envelope.envelopeId, {
114+
customFields: {
115+
textCustomFields: [
116+
{
117+
name: "mailingListId",
118+
required: "false",
119+
show: "false",
120+
value: bulkList.listId,
121+
},
122+
],
123+
},
124+
});
125+
// Step 5 end
116126

117-
// Step 5. Add placeholder recipients
118-
// These will be replaced by the details provided in the Bulk List uploaded during Step 3
119-
// Note: The name / email format used is:
120-
// Name: Multi Bulk Recipients::{rolename}
121-
// Email: MultiBulkRecipients-{rolename}@docusign.com
122-
await envelopeApi.createRecipient(args.accountId, envelope.envelopeId, {
123-
recipients: {
124-
signers: [
125-
{
126-
name: "Multi Bulk Recipient::signer",
127-
email: "multiBulkRecipients-signer@docusign.com",
128-
roleName: "signer",
129-
routingOrder: "1",
130-
status: "created",
131-
deliveryMethod: "email",
132-
recipientId: "1",
133-
recipientType: "signer",
134-
tabs: docusign.Tabs.constructFromObject({
135-
signHereTabs: [docusign.SignHere.constructFromObject({
136-
anchorString: "/sn1/",
137-
anchorYOffset: "10",
138-
anchorUnits: "pixels",
139-
anchorXOffset: "20",
140-
})],
141-
})
142-
},
143-
{
144-
name: "Multi Bulk Recipient::cc",
145-
email: "multiBulkRecipients-cc@docusign.com",
146-
roleName: "cc",
147-
routingOrder: "1",
148-
status: "created",
149-
deliveryMethod: "email",
150-
recipientId: "2",
151-
recipientType: "cc",
152-
},
153-
],
154-
},
155-
});
127+
// Add placeholder recipients
128+
// These will be replaced by the details provided in the Bulk List uploaded during Step 3
129+
// Note: The name / email format used is:
130+
// Name: Multi Bulk Recipients::{rolename}
131+
// Email: MultiBulkRecipients-{rolename}@docusign.com
132+
// Step 6 start
133+
await envelopeApi.createRecipient(args.accountId, envelope.envelopeId, {
134+
recipients: {
135+
signers: [
136+
{
137+
name: "Multi Bulk Recipient::signer",
138+
email: "multiBulkRecipients-signer@docusign.com",
139+
roleName: "signer",
140+
routingOrder: "1",
141+
status: "created",
142+
deliveryMethod: "email",
143+
recipientId: "1",
144+
recipientType: "signer",
145+
}
146+
],
147+
carbonCopies: [
148+
{
149+
name: "Multi Bulk Recipient::cc",
150+
email: "multiBulkRecipients-cc@docusign.com",
151+
roleName: "cc",
152+
routingOrder: "1",
153+
status: "created",
154+
deliveryMethod: "email",
155+
recipientId: "2",
156+
recipientType: "cc",
157+
},
158+
],
159+
},
160+
});
161+
// Step 6 end
156162

157-
//Step 6: Initiate the Bulk Send by posting your listId, and the envelopeId
158-
let bulkResult = await bulkEnvelopesApi.createBulkSendRequest(
159-
args.accountId,
160-
bulkList.listId,
161-
{
162-
bulkSendRequest: {
163-
envelopeOrTemplateId: envelope.envelopeId,
164-
},
165-
}
166-
);
163+
//Initiate the Bulk Send by posting your listId, and the envelopeId
164+
// Step 7 start
165+
let bulkResult = await bulkEnvelopesApi.createBulkSendRequest(
166+
args.accountId,
167+
bulkList.listId,
168+
{
169+
bulkSendRequest: {
170+
envelopeOrTemplateId: envelope.envelopeId,
171+
},
172+
}
173+
);
174+
// Step 7 end
167175

168-
// Step 7. Confirm successful bulk send
169-
let results = await bulkEnvelopesApi.getBulkSendBatchStatus(
170-
args.accountId,
171-
bulkResult.batchId
172-
);
176+
// Confirm successful bulk send
177+
// Step 8 start
178+
let results = await bulkEnvelopesApi.getBulkSendBatchStatus(
179+
args.accountId,
180+
bulkResult.batchId
181+
);
182+
// Step 8 end
173183

174-
return results;
175-
};
184+
return results;
185+
};
176186

177-
module.exports = { bulkSendEnvelopes };
187+
module.exports = { bulkSendEnvelopes };

0 commit comments

Comments
 (0)