Skip to content

Commit 40eac11

Browse files
author
Raileen Del Rosario
committed
2 parents f631e2f + 9cb3f6d commit 40eac11

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
@@ -1022,20 +1022,24 @@ function startMaestro {
10221022
do {
10231023
Enum listMaestroExamples {
10241024
triggerWorkflow = 1;
1025-
Pick_An_API = 2;
1025+
cancelWorkflow = 4;
1026+
Pick_An_API = 5;
10261027
}
10271028
$listMaestroExamplesView = $null;
10281029
do {
10291030
Write-Output ""
10301031
Write-Output 'Select the action: '
10311032
Write-Output "$([int][listMaestroExamples]::triggerWorkflow)) How to trigger a Maestro workflow"
1033+
Write-Output "$([int][listMaestroExamples]::cancelWorkflow)) How to cancel a Maestro workflow"
10321034
Write-Output "$([int][listMaestroExamples]::Pick_An_API)) Pick_An_API"
10331035
[int]$listMaestroExamplesView = Read-Host "Select the action"
10341036
} while (-not [listMaestroExamples]::IsDefined([listMaestroExamples], $listMaestroExamplesView));
10351037

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

1041+
} elseif ($listMaestroExamplesView -eq [listMaestroExamples]::cancelWorkflow) {
1042+
Invoke-Script -Command "`".\examples\Maestro\eg004CancelWorkflow.ps1`""
10391043
}
10401044

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

0 commit comments

Comments
 (0)