-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworking.js
100 lines (85 loc) · 2.25 KB
/
working.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
const fs = require('fs');
require('dotenv').config();
const {
BASE_URL,
ACCOUNT_ID,
ACCESS_TOKEN,
} = process.env;
const instance = require('axios').create({
baseURL: `${BASE_URL}/accounts/${ACCOUNT_ID}`,
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`,
},
});
(async () => {
if (!BASE_URL || !ACCOUNT_ID || !ACCESS_TOKEN) {
console.error('Missing env vars!');
return;
}
const clientUserId = Date.now();
const name = 'Yulian Ovdey';
const email = '[email protected]';
async function createEnvelope() {
const result = await instance.post('/envelopes', {
status: 'sent',
emailSubject: 'Please sign',
documents: [
{
documentId: 1,
name: 'Test Document',
documentBase64: fs.readFileSync('Empty Test PDF.pdf').toString('base64'),
fileExtension: 'pdf',
},
],
recipients: {
signers: [
{
name,
recipientId: 1,
clientUserId,
email,
tabs: {
signHereTabs: [
{
documentId: 1,
pageNumber: 1,
anchorXOffset: 0,
anchorYOffset: 0,
name: 'Please sign here',
},
],
},
},
],
},
});
return result.data.envelopeId;
}
async function createRecipientView(envelopeId) {
const result = await instance.post(`/envelopes/${envelopeId}/views/recipient`, {
clientUserId,
recipientId: 1,
userName: name,
email,
authenticationMethod: 'None',
returnUrl: 'http://localhost:3000',
});
console.log(result.data);
}
const envelopeId = await createEnvelope();
await createRecipientView(envelopeId);
// Wait 30 seconds
//
// During this timeout - visit the recipient URL from the call above and
// update the recipient's name in the "Adopt Your Signature" modal
await new Promise((resolve) => {
setTimeout(resolve, 30000);
});
try {
await createRecipientView(envelopeId);
console.log('Success!');
} catch (e) {
console.log(`Creating another recipient view failed:`, e.response.data.message);
}
})();