forked from docusign/docusign-esign-node-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
promise.js
59 lines (56 loc) · 2.57 KB
/
promise.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var docusign = require('docusign');
var DocuSignError = docusign.DocuSignError;
var integratorKey = '***'; // Integrator Key associated with your DocuSign Integration
var email = 'YOUR_EMAIL'; // Email for your DocuSign Account
var password = 'YOUR_PASSWORD'; // Password for your DocuSign Account
var docusignEnv = 'demo'; // DocuSign Environment generally demo for testing purposes
var fullName = 'Joan Jett'; // Recipient's Full Name
var templateId = '***'; // ID of the Template you want to create the Envelope with
var templateRoleName = '***'; // Role Name of the Template
var debug = false; // Enable debug logging and debug responses from API
var templateRoles = [{
email: email,
name: fullName,
roleName: templateRoleName
}];
// **********************************************************************************
// Step 1 - Initialize DocuSign Object with Integrator Key and Desired Environment
// **********************************************************************************
docusign.init(integratorKey, docusignEnv, debug)
// **********************************************************************************
// Step 2 - Create a DocuSign Client Object
// **********************************************************************************
.then(function (response) {
if (response.message === 'succesfully initialized') {
return docusign.createClient(email, password);
} else {
throw new Error('Did not initialize');
}
})
// **********************************************************************************
// Step 3 - Request Signature via Template
// **********************************************************************************
.then(function (client) {
return [client, client.envelopes.sendTemplate('Sent from a Template', templateId, templateRoles)];
})
.spread(function (client, response) {
console.log('The envelope information of the created envelope is: \n' + JSON.stringify(response));
return client;
})
// **********************************************************************************
// Step 4 - Revoke OAuth Token for Logout
// **********************************************************************************
.then(function (client) {
return client.logOut();
})
.catch(DocuSignError, function (dsError) {
console.log('DocuSignError: ', dsError.stack || dsError);
process.exit(1);
})
.catch(function (error) {
console.log('Error: ', error.stack || error);
process.exit(1);
})
.finally(function () {
process.exit();
});