Repository navigation
Expand file tree
/
Copy pathSolutionCode.sh
More file actions
executable file
·101 lines (77 loc) · 3.1 KB
/
Copy pathSolutionCode.sh
File metadata and controls
executable file
·101 lines (77 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
source ./utils/utils.sh
# Trigger a new instance of a workflow
#
# Check that we're in a bash shell
if [[ $SHELL != *"bash"* ]]; then
echo "PROBLEM: Run these scripts from within the bash shell."
fi
# Obtain your OAuth token. This is handled for you by the shell program.
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
# Set up variables for full code example
account_id=$(cat config/API_ACCOUNT_ID)
base_path="https://api-d.docusign.com/v1"
# Construct your API headers
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
'--header' "Accept: application/json" \
'--header' "Content-Type: application/json")
# Copy your workflow ID into the variable below
# Hint: Get your workflow ID from the Maestro UI or through an API call
workflow_id='YOUR_WORKFLOW_ID'
# Get the trigger URL of your workflow
response=$(mktemp /tmp/response-wftmp.XXXXXX)
Status=$(curl -s -w "%{http_code}\n" -i --request GET "${base_path}/accounts/${account_id}/workflows/${workflow_id}/trigger-requirements" \
"${Headers[@]}" \
--output ${response})
# If the status code returned is greater than 201 (OK / Accepted), display an error message with the API response.
if [[ "$Status" -gt "201" ]]; then
echo ""
echo "Unable to get the trigger requirements of the specified workflow ${workflow_id}"
echo ""
cat $response
exit 0
fi
cat $response
echo ""
# Decoding the trigger URL so it can be used in the the next API call
trigger_url=$(grep '"url":' $response | sed -n 's/.*"url": "\([^"]*\)".*/\1/p')
decoded_trigger_url=$(echo $trigger_url | sed 's/\\u0026/\&/g')
# Construct your request body with the required trigger inputs for your workflow
# Hint: Find the structure of the trigger inputs in the response of your API call to get the trigger requirements
request_data=$(mktemp /tmp/request-wf-001.XXXXXX)
instance_name='New Instance'
printf \
'{
"instance_name": "'"$instance_name"'",
"trigger_inputs": {
}
}' >$request_data
response=$(mktemp /tmp/response-wftmp.XXXXXX)
# The ${decoded_trigger_url} variable is extracted from the response from a previous API call
# to the Workflows: getWorkflowTriggerRequirements endpoint.
Status=$(curl -s -w "%{http_code}\n" -i --request POST ${decoded_trigger_url} \
"${Headers[@]}" \
--data-binary @${request_data} \
--output ${response})
instance_id=$(grep '"instance_id":' $response | sed -n 's/.*"instance_id": "\([^"]*\)".*/\1/p')
# Store the instance_id into the config file
echo "${instance_id}" > config/INSTANCE_ID
echo ""
echo "Response:"
cat $response
echo ""
instance_url=$(grep '"instance_url":' $response | sed -n 's/.*"instance_url": "\([^"]*\)".*/\1/p')
decoded_instance_url=$(echo $instance_url | sed 's/\\u0026/\&/g')
echo "$decoded_instance_url" > config/INSTANCE_URL
echo ""
echo "Use this URL to complete the workflow steps:"
echo $decoded_instance_url
sleep 3
echo ""
echo "Opening a browser with the embedded workflow..."
sleep 5
# [Optional] Launch local server and embed workflow instance using the instance URL
embedWorkflow "$decoded_instance_url"
# Remove the temporary files
rm "$request_data"
rm "$response"