Skip to content

Commit 2e8220d

Browse files
author
nianiB9
committed
Merge branch 'DEVDOCS-16858' into DEVDOCS-16852
2 parents f326ab1 + 0d2d340 commit 2e8220d

File tree

4 files changed

+147
-3
lines changed

4 files changed

+147
-3
lines changed

examples/Maestro/eg001TriggerWorkflow.sh

Lines changed: 2 additions & 3 deletions
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
@@ -150,9 +149,9 @@ Status=$(curl -s -w "%{http_code}\n" -i --request POST ${decoded_trigger_url} \
150149
#ds-snippet-end:Maestro1Step5
151150

152151

153-
instance_id=`cat $response | grep instance_id | sed 's/.*\"instance_id\":\"//' | sed 's/\".*//'`
152+
instance_id=$(grep '"instance_id":' $response | sed -n 's/.*"instance_id": "\([^"]*\)".*/\1/p')
154153
# Store the instance_id into the config file
155-
echo $instance_id >config/INSTANCE_ID
154+
echo "${instance_id}" > config/INSTANCE_ID
156155

157156
echo ""
158157
echo "Response:"
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: 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,8 @@ function startMaestro() {
975975
PS3='Select the action : '
976976
select CHOICE in \
977977
"Trigger_Workflow" \
978+
"Pause_Workflow" \
979+
"Cancel_Workflow" \
978980
"Home"; do
979981
case "$CHOICE" in
980982
Home)
@@ -984,6 +986,14 @@ function startMaestro() {
984986
bash examples/Maestro/eg001TriggerWorkflow.sh
985987
startMaestro
986988
;;
989+
Pause_Workflow)
990+
bash examples/Maestro/eg002PauseWorkflow.sh
991+
startMaestro
992+
;;
993+
Cancel_Workflow)
994+
bash examples/Maestro/eg004CancelWorkflow.sh
995+
startMaestro
996+
;;
987997
*)
988998
echo "Default action..."
989999
startMaestro

0 commit comments

Comments
 (0)