Skip to content

Commit bfdc1f4

Browse files
author
Raileen Del Rosario
committed
adding maestro example 4
1 parent c2b89a7 commit bfdc1f4

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

examples/Maestro/eg001TriggerWorkflow.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $headers.add("Content-Type", "application/json")
3737
$headers.add("Accept", "application/json")
3838
#ds-snippet-end:Maestro1Step2
3939

40-
Write-Output "Attempting to retrieve Workflow definition..."
40+
Write-Output "Attempting to retrieve the workflow definition..."
4141

4242
#ds-snippet-start:Maestro1Step3
4343
Invoke-RestMethod `
@@ -75,13 +75,21 @@ if (-not ([string]::IsNullOrEmpty($triggerUrl))) {
7575
#ds-snippet-start:Maestro1Step5
7676
$triggerResult = Invoke-WebRequest -uri $triggerUrl -headers $headers -body $body -method POST -UseBasicParsing
7777
#ds-snippet-end:Maestro1Step5
78+
Write-Host $triggerResult
79+
Write-Host ""
80+
81+
$workflowInstanceId = $($triggerResult | ConvertFrom-Json).instance_id
82+
$workflowInstanceId | Out-File -FilePath "config/INSTANCE_ID" -Encoding utf8 -Force
83+
Write-Host "Successfully created and published workflow $workflowInstanceId, ID saved to config/INSTANCE_ID"
84+
7885

7986
$instanceUrl = $($triggerResult | ConvertFrom-Json).instance_url
8087
# Decode escaped characters
8188
$instanceUrl = $instanceUrl -replace "\\u0026", "&"
8289
Write-Host "Use this URL to complete the workflow steps:"
8390
Write-Host $instanceUrl
8491

92+
8593
Write-Host ""
8694
Write-Host "Opening a browser with the embedded workflow..."
8795

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Cancel a workflow instance
2+
3+
# Check that there is a workflow
4+
if (Test-Path .\config\WORKFLOW_ID) {
5+
$workflowId = Get-Content .\config\WORKFLOW_ID
6+
} else {
7+
Write-Output "Please run example 1 to create and trigger a workflow before running this example,"
8+
exit 0
9+
}
10+
11+
# Check that there is a running workflow instance to cancel
12+
if (Test-Path .\config\INSTANCE_ID) {
13+
$workflowInstanceId = Get-Content .\config\INSTANCE_ID
14+
} else {
15+
Write-Output "Please run example 1 to trigger a workflow before running this example."
16+
exit 0
17+
}
18+
19+
$base_path = "https://api-d.docusign.com/v1"
20+
21+
# Step 1: Obtain your OAuth token
22+
# Note: Substitute these values with your own
23+
$accessToken = Get-Content .\config\ds_access_token.txt
24+
25+
# Set up variables for full code example
26+
# Note: Substitute these values with your own
27+
$apiAccountId = Get-Content .\config\API_ACCOUNT_ID
28+
29+
# temp file:
30+
$response = New-TemporaryFile
31+
32+
# Construct your API headers
33+
#ds-snippet-start:Maestro4Step2
34+
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
35+
$headers.add("Authorization", "Bearer $accessToken")
36+
$headers.add("Content-Type", "application/json")
37+
$headers.add("Accept", "application/json")
38+
#ds-snippet-end:Maestro4Step2
39+
40+
Write-Output "Attempting to cancel the Workflow instance..."
41+
42+
#ds-snippet-start:Maestro4Step3
43+
Invoke-RestMethod `
44+
-Uri "${base_path}/accounts/${apiAccountId}/workflows/${workflowId}/instances/${workflowInstanceId}/actions/cancel" `
45+
-Method 'POST' `
46+
-Headers $headers `
47+
-OutFile $response
48+
49+
#Write-Output "Workflow instance $workflowInstanceId has been canceled."
50+
Write-Output "Response: $(Get-Content -Raw $response)"
51+
#ds-snippet-end:Maestro4Step3
52+
53+
# cleanup
54+
Remove-Item $response
55+
56+
Write-Output "Done."

launcher.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,20 +1014,24 @@ function startMaestro {
10141014
do {
10151015
Enum listMaestroExamples {
10161016
triggerWorkflow = 1;
1017-
Pick_An_API = 2;
1017+
cancelWorkflow = 4;
1018+
Pick_An_API = 5;
10181019
}
10191020
$listMaestroExamplesView = $null;
10201021
do {
10211022
Write-Output ""
10221023
Write-Output 'Select the action: '
10231024
Write-Output "$([int][listMaestroExamples]::triggerWorkflow)) How to trigger a Maestro workflow"
1025+
Write-Output "$([int][listMaestroExamples]::cancelWorkflow)) How to cancel a Maestro workflow"
10241026
Write-Output "$([int][listMaestroExamples]::Pick_An_API)) Pick_An_API"
10251027
[int]$listMaestroExamplesView = Read-Host "Select the action"
10261028
} while (-not [listMaestroExamples]::IsDefined([listMaestroExamples], $listMaestroExamplesView));
10271029

10281030
if ($listMaestroExamplesView -eq [listMaestroExamples]::triggerWorkflow) {
10291031
Invoke-Script -Command "`".\examples\Maestro\eg001TriggerWorkflow.ps1`""
10301032

1033+
} elseif ($listMaestroExamplesView -eq [listMaestroExamples]::cancelWorkflow) {
1034+
Invoke-Script -Command "`".\examples\Maestro\eg004CancelWorkflow.ps1`""
10311035
}
10321036

10331037
} until ($listMaestroExamplesView -eq [listMaestroExamples]::Pick_An_API)

0 commit comments

Comments
 (0)