|
| 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." |
0 commit comments