Skip to content

Commit 6041d71

Browse files
authored
Merge pull request #122 from docusign/DEVDOCS-16852
[DEVDOCS-16852] Resume Maestro Workflow Example
2 parents 078c107 + d704576 commit 6041d71

File tree

5 files changed

+216
-1
lines changed

5 files changed

+216
-1
lines changed

examples/Maestro/eg001TriggerWorkflow.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
# https://developers.docusign.com/docs/workflows-api/trigger-workflow
32
# Trigger a new instance of a workflow
43
#
54
# Check that we're in a bash shell
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# Pause a running workflow instance
3+
#
4+
# Check that we're in a bash shell
5+
if [[ $SHELL != *"bash"* ]]; then
6+
echo "PROBLEM: Run these scripts from within the bash shell."
7+
fi
8+
9+
# Check that there is a workflow
10+
workflow_id=$(cat config/WORKFLOW_ID)
11+
if [ -z "$workflow_id" ]; then
12+
echo "Please run example 1 to create and trigger a worklow before running this example."
13+
exit 0
14+
fi
15+
16+
# Obtain your OAuth token
17+
# Note: Substitute these values with your own
18+
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
19+
20+
21+
# Set up variables for full code example
22+
# Note: Substitute these values with your own
23+
ACCOUNT_ID=$(cat config/API_ACCOUNT_ID)
24+
25+
base_path="https://api-d.docusign.com/v1"
26+
27+
# Construct your API headers
28+
#ds-snippet-start:Maestro2Step2
29+
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
30+
'--header' "Accept: application/json" \
31+
'--header' "Content-Type: application/json")
32+
#ds-snippet-end:Maestro2Step2
33+
echo ""
34+
echo "Attempting to pause the Workflow.."
35+
echo ""
36+
37+
#ds-snippet-start:Maestro2Step3
38+
response=$(mktemp /tmp/response-wftmp.XXXXXX)
39+
Status=$(
40+
curl -w '%{http_code}' --request POST "${base_path}/accounts/${ACCOUNT_ID}/workflows/${workflow_id}/actions/pause" \
41+
"${Headers[@]}" \
42+
--output ${response}
43+
)
44+
# If the status code returned is greater than 201 (OK / Accepted), display an error message with the API response.
45+
if [[ "$Status" -gt "201" ]]; then
46+
echo ""
47+
echo "Unable to retrieve workflow instance: ${WORKFLOW_INSTANCE_ID}"
48+
echo ""
49+
cat $response
50+
exit 0
51+
fi
52+
53+
echo ""
54+
echo "Workflow has been paused."
55+
echo ""
56+
echo ""
57+
echo "Response:"
58+
cat $response
59+
echo ""
60+
echo ""
61+
#ds-snippet-end:Maestro2Step3
62+
63+
# Remove the temporary files
64+
rm "$response"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# Resume a paused workflow instance
3+
#
4+
# Check that we're in a bash shell
5+
if [[ $SHELL != *"bash"* ]]; then
6+
echo "PROBLEM: Run these scripts from within the bash shell."
7+
fi
8+
9+
# Check that there is a workflow
10+
workflow_id=$(cat config/WORKFLOW_ID)
11+
if [ -z "$workflow_id" ]; then
12+
echo "Please run example 1 to create and trigger a workflow before running this example."
13+
exit 0
14+
fi
15+
16+
# Obtain your OAuth token
17+
# Note: Substitute these values with your own
18+
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
19+
20+
# Set up variables
21+
# Note: Substitute these values with your own
22+
ACCOUNT_ID=$(cat config/API_ACCOUNT_ID)
23+
base_path="https://api-d.docusign.com/v1"
24+
25+
# Construct your API headers
26+
#apx-snippet-start:ResumeWorkflow
27+
#ds-snippet-start:Maestro3Step2
28+
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
29+
'--header' "Accept: application/json" \
30+
'--header' "Content-Type: application/json")
31+
#ds-snippet-end:Maestro3Step2
32+
#apx-snippet-end:ResumeWorkflow
33+
34+
echo ""
35+
echo "Attempting to resume the Workflow..."
36+
echo ""
37+
38+
# Make the API call to resume
39+
#apx-snippet-start:ResumeWorkflow
40+
#ds-snippet-start:Maestro3Step3
41+
response=$(mktemp /tmp/response-wftmp.XXXXXX)
42+
Status=$(
43+
curl -w '%{http_code}' --request POST "${base_path}/accounts/${ACCOUNT_ID}/workflows/${workflow_id}/actions/resume" \
44+
"${Headers[@]}" \
45+
--output ${response}
46+
)
47+
48+
if [[ "$Status" -gt "201" ]]; then
49+
echo ""
50+
echo "Unable to resume workflow: ${workflow_id}"
51+
echo ""
52+
cat $response
53+
exit 0
54+
fi
55+
56+
echo ""
57+
echo "Workflow has been resumed."
58+
echo ""
59+
echo "Response:"
60+
cat $response
61+
echo ""
62+
#ds-snippet-end:Maestro3Step3
63+
#apx-snippet-end:ResumeWorkflow
64+
65+
# Remove the temporary files
66+
rm "$response"
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# Cancel a running workflow instance
3+
#
4+
# Check that we're in a bash shell
5+
if [[ $SHELL != *"bash"* ]]; then
6+
echo "PROBLEM: Run these scripts from within the bash shell."
7+
fi
8+
9+
# Check that there is a workflow
10+
workflow_id=$(cat config/WORKFLOW_ID)
11+
if [ -z "$workflow_id" ]; then
12+
echo "Please run example 1 to create and trigger a worklow before running this example."
13+
exit 0
14+
fi
15+
16+
# Check that there is a running workflow instance to cancel
17+
WORKFLOW_INSTANCE_ID=$(cat config/INSTANCE_ID)
18+
if [ -z "$WORKFLOW_INSTANCE_ID" ]; then
19+
echo "Please run example 1 to trigger a workflow before running this example."
20+
exit 0
21+
fi
22+
23+
# Obtain your OAuth token
24+
# Note: Substitute these values with your own
25+
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
26+
27+
28+
# Set up variables for full code example
29+
# Note: Substitute these values with your own
30+
ACCOUNT_ID=$(cat config/API_ACCOUNT_ID)
31+
32+
base_path="https://api-d.docusign.com/v1"
33+
34+
# Construct your API headers
35+
#ds-snippet-start:Maestro4Step2
36+
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
37+
'--header' "Accept: application/json" \
38+
'--header' "Content-Type: application/json")
39+
#ds-snippet-end:Maestro4Step2
40+
echo ""
41+
echo "Attempting to cancel the Workflow instance..."
42+
echo ""
43+
44+
#ds-snippet-start:Maestro4Step3
45+
response=$(mktemp /tmp/response-wftmp.XXXXXX)
46+
Status=$(
47+
curl -w '%{http_code}' --request POST "${base_path}/accounts/${ACCOUNT_ID}/workflows/${workflow_id}/instances/${WORKFLOW_INSTANCE_ID}/actions/cancel" \
48+
"${Headers[@]}" \
49+
--output ${response}
50+
)
51+
# If the status code returned is greater than 201 (OK / Accepted), display an error message with the API response.
52+
if [[ "$Status" -gt "201" ]]; then
53+
echo ""
54+
echo "Unable to retrieve workflow instance: ${WORKFLOW_INSTANCE_ID}"
55+
echo ""
56+
cat $response
57+
exit 0
58+
fi
59+
60+
echo ""
61+
echo "Workflow has been canceled."
62+
echo ""
63+
echo ""
64+
echo "Response:"
65+
cat $response
66+
echo ""
67+
echo ""
68+
#ds-snippet-end:Maestro4Step3
69+
70+
# Remove the temporary files
71+
rm "$response"

launcher.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,9 @@ function startMaestro() {
975975
PS3='Select the action : '
976976
select CHOICE in \
977977
"Trigger_Workflow" \
978+
"Pause_Workflow" \
979+
"Resume_Workflow" \
980+
"Cancel_Workflow" \
978981
"Home"; do
979982
case "$CHOICE" in
980983
Home)
@@ -984,6 +987,18 @@ function startMaestro() {
984987
bash examples/Maestro/eg001TriggerWorkflow.sh
985988
startMaestro
986989
;;
990+
Pause_Workflow)
991+
bash examples/Maestro/eg002PauseWorkflow.sh
992+
startMaestro
993+
;;
994+
Resume_Workflow)
995+
bash examples/Maestro/eg003ResumeWorkflow.sh
996+
startMaestro
997+
;;
998+
Cancel_Workflow)
999+
bash examples/Maestro/eg004CancelWorkflow.sh
1000+
startMaestro
1001+
;;
9871002
*)
9881003
echo "Default action..."
9891004
startMaestro

0 commit comments

Comments
 (0)