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