Skip to content

Commit 085b87c

Browse files
author
Raileen Del Rosario
committed
remote web forms code example
1 parent 5b8d22f commit 085b87c

File tree

3 files changed

+93
-3
lines changed

3 files changed

+93
-3
lines changed

demo_documents/web-form-config.json

Lines changed: 1 addition & 2 deletions
Large diffs are not rendered by default.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
. "utils/invokeScript.ps1"
2+
3+
$apiUri = "https://apps-d.docusign.com/api/webforms/v1.1"
4+
$configPath = ".\config\settings.json"
5+
$tokenPath = ".\config\ds_access_token.txt"
6+
$accountIdPath = ".\config\API_ACCOUNT_ID"
7+
8+
# Get required variables from .\config\settings.json file
9+
$config = Get-Content $configPath -Raw | ConvertFrom-Json
10+
$signerName = $config.SIGNER_NAME
11+
$signerEmail = $config.SIGNER_EMAIL
12+
13+
$accessToken = Get-Content $tokenPath
14+
$accountId = Get-Content $accountIdPath
15+
16+
# Create template for the Web Form from the API
17+
Invoke-Script -Command "`".\utils\createWebFormTemplate.ps1`""
18+
19+
$templateId = Get-Content -Path ".\config\WEB_FORM_TEMPLATE_ID"
20+
21+
$webFormConfig = Get-Content -Raw demo_documents\web-form-config.json
22+
$result = $webFormConfig -replace "template-id", $templateId
23+
$result | Set-Content -Path demo_documents\web-form-config.json
24+
25+
Write-Host ""
26+
Write-Host "Go to your Docusign account to create the Web Form. Go to 'Templates' in your developer account, select 'Start,' select 'Web Forms,' and choose 'Upload Web Form.' Upload the JSON config file 'web-form-config.json' found under the demo_documents folder of this project. You will need to activate the web form before proceeding. Press any key to continue after doing so."
27+
$choice = Read-Host
28+
29+
#ds-snippet-start:WebForms2Step2
30+
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
31+
$headers.add("Authorization", "Bearer $accessToken")
32+
$headers.add("Content-Type", "application/json")
33+
$headers.add("Accept", "application/json")
34+
#ds-snippet-end:WebForms2Step2
35+
36+
# List web forms in account that match the name of the web form we just created
37+
#ds-snippet-start:WebForms2Step3
38+
$response = New-TemporaryFile
39+
Invoke-RestMethod `
40+
-Uri "${apiUri}/accounts/${accountId}/forms?search=Web%20Form%20Example%20Template" `
41+
-Method 'GET ' `
42+
-Headers $headers `
43+
-OutFile $response
44+
45+
$formId = $(Get-Content $response | ConvertFrom-Json).items[0].id
46+
#ds-snippet-end:WebForms2Step3
47+
48+
#ds-snippet-start:WebForms2Step4
49+
$json = @"
50+
{
51+
"sendOption": "now",
52+
"formValues": {
53+
"PhoneNumber": "555-555-5555",
54+
"Yes": ["Yes"],
55+
"Company": "Tally",
56+
"JobTitle": "Programmer Writer"
57+
},
58+
"recipients": [
59+
{
60+
"roleName": "signer",
61+
"name": "$signerName",
62+
"email": "$signerEmail"
63+
}
64+
]
65+
}
66+
"@
67+
#ds-snippet-end:WebForms2Step4
68+
69+
#ds-snippet-start:WebForms2Step5
70+
Invoke-RestMethod `
71+
-Uri "${apiUri}/accounts/${accountId}/forms/${formId}/instances" `
72+
-Method 'POST' `
73+
-Headers $headers `
74+
-Body $json `
75+
-OutFile $response
76+
77+
$responseContent = $(Get-Content $response | ConvertFrom-Json)
78+
#ds-snippet-end:WebForms2Step5
79+
80+
Write-Host ""
81+
Write-Host "Creating a new remote instance of the web form..."
82+
Write-Host ""
83+
Write-Host "Response:"
84+
Write-Host $responseContent
85+
86+
Write-Output ""
87+
Write-Output "Done."

launcher.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,19 +1000,23 @@ function startWebForms {
10001000
do {
10011001
Enum listWebFormsExamples {
10021002
createInstance = 1;
1003-
Pick_An_API = 2;
1003+
createRemoteInstance = 2;
1004+
Pick_An_API = 3;
10041005
}
10051006
$listWebFormsExamplesView = $null;
10061007
do {
10071008
Write-Output ""
10081009
Write-Output 'Select the action: '
10091010
Write-Output "$([int][listWebFormsExamples]::createInstance)) Create_Instance"
1011+
Write-Output "$([int][listWebFormsExamples]::createRemoteInstance)) Create_Remote_Instance"
10101012
Write-Output "$([int][listWebFormsExamples]::Pick_An_API)) Pick_An_API"
10111013
[int]$listWebFormsExamplesView = Read-Host "Select the action"
10121014
} while (-not [listWebFormsExamples]::IsDefined([listWebFormsExamples], $listWebFormsExamplesView));
10131015

10141016
if ($listWebFormsExamplesView -eq [listWebFormsExamples]::createInstance) {
10151017
Invoke-Script -Command "`".\examples\WebForms\eg001CreateInstance.ps1`""
1018+
} elseif ($listWebFormsExamplesView -eq [listWebFormsExamples]::createRemoteInstance) {
1019+
Invoke-Script -Command "`".\examples\WebForms\eg002CreateRemoteInstance.ps1`""
10161020
}
10171021
} until ($listWebFormsExamplesView -eq [listWebFormsExamples]::Pick_An_API)
10181022
startLauncher

0 commit comments

Comments
 (0)