-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcreateWebFormTemplate.ps1
More file actions
157 lines (140 loc) · 5.24 KB
/
createWebFormTemplate.ps1
File metadata and controls
157 lines (140 loc) · 5.24 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
$apiUri = "https://demo.docusign.net/restapi"
$accessToken = Get-Content .\config\ds_access_token.txt
$accountId = Get-Content .\config\API_ACCOUNT_ID
Write-Output "Checking to see if the template already exists in your account..."
$templateName = "Web Form Example Template"
$response = New-TemporaryFile
Invoke-RestMethod `
-Uri "${apiUri}/v2.1/accounts/${accountId}/templates" `
-Method 'GET' `
-Headers @{
'Authorization' = "Bearer $accessToken";
'Content-Type' = "application/json";
} `
-Body @{ 'search_text' = $templateName } `
-OutFile $response
$templateId = $(Get-Content $response | ConvertFrom-Json).envelopeTemplates.templateId
Write-Output "Did we find any templateIds?: $templateId"
if (-not ([string]::IsNullOrEmpty($templateId))) {
Write-Output "Your account already includes the '${templateName}' template."
Write-Output "${templateId}" > .\config\WEB_FORM_TEMPLATE_ID
Remove-Item $response
Write-Output "Done."
exit 0
}
$requestData = New-TemporaryFile
$requestDataTemp = New-TemporaryFile
$doc1Base64 = New-TemporaryFile
Write-Output "Sending the template create request to Docusign..."
[Convert]::ToBase64String([System.IO.File]::ReadAllBytes((Resolve-Path ".\demo_documents/World_Wide_Corp_Web_Form.pdf"))) > $doc1Base64
$json = @"
{
"description": "Example template created via the API",
"name": "Web Form Example Template",
"shared": "false",
"documents": [
{
"documentBase64": "$(Get-Content $doc1Base64)",
"documentId": "1",
"fileExtension": "pdf",
"name": "World_Wide_Web_Form"
}
],
"emailSubject": "Please sign this document",
"recipients": {
"signers": [
{
"recipientId": "1",
"roleName": "signer",
"routingOrder": "1",
"tabs": {
"checkboxTabs": [
{
"documentId": "1",
"tabLabel": "Yes",
"anchorString": "/SMS/",
"anchorUnits": "pixels",
"anchorXOffset": "0",
"anchorYOffset": "0"
}
],
"signHereTabs": [
{
"documentId": "1",
"tabLabel": "Signature",
"anchorString": "/SignHere/",
"anchorUnits": "pixels",
"anchorXOffset": "20",
"anchorYOffset": "10"
}
],
"textTabs": [
{
"documentId": "1",
"tabLabel": "FullName",
"anchorString": "/FullName/",
"anchorUnits": "pixels",
"anchorXOffset": "0",
"anchorYOffset": "0"
},
{
"documentId": "1",
"tabLabel": "PhoneNumber",
"anchorString": "/PhoneNumber/",
"anchorUnits": "pixels",
"anchorXOffset": "0",
"anchorYOffset": "0"
},
{
"documentId": "1",
"tabLabel": "Company",
"anchorString": "/Company/",
"anchorUnits": "pixels",
"anchorXOffset": "0",
"anchorYOffset": "0"
},
{
"documentId": "1",
"tabLabel": "JobTitle",
"anchorString": "/Title/",
"anchorUnits": "pixels",
"anchorXOffset": "0",
"anchorYOffset": "0"
}
],
"dateSignedTabs": [
{
"documentId": "1",
"tabLabel": "DateSigned",
"anchorString": "/Date/",
"anchorUnits": "pixels",
"anchorXOffset": "0",
"anchorYOffset": "0"
}
]
}
}
]
},
"status": "created"
}
"@
Invoke-RestMethod `
-Uri "${apiUri}/v2.1/accounts/${accountId}/templates" `
-Method 'POST' `
-Headers @{
'Authorization' = "Bearer $accessToken";
'Content-Type' = "application/json";
} `
-Body $json `
-OutFile $response
Write-Output "Results:"
Get-Content $response
$templateId = $(Get-Content $response | ConvertFrom-Json).templateId
Write-Output "Template '${templateName}' was created! Template ID ${templateId}."
Write-Output ${templateId} > .\config\WEB_FORM_TEMPLATE_ID
Remove-Item $requestData
Remove-Item $requestDataTemp
Remove-Item $response
Remove-Item $doc1Base64
Write-Output "Done."