Skip to content

Commit fef7396

Browse files
author
nianiB9
committed
update
1 parent bcc77b8 commit fef7396

File tree

1 file changed

+29
-52
lines changed

1 file changed

+29
-52
lines changed
Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,44 @@
11
#!/bin/bash
2-
# https://developers.docusign.com/docs/maestro-api/maestro101/embed-workflow/
3-
# Generates an embeddable Maestro workflow URL using the workflow ID
2+
# Embed a Maestro workflow instance using the URL returned from triggerWorkflow
43

5-
# Ensure bash shell
4+
# Ensure the script is run in a bash shell
65
if [[ $SHELL != *"bash"* ]]; then
76
echo "PROBLEM: Run these scripts from within the bash shell."
87
exit 1
98
fi
109

11-
# Step 1: Load required config values
12-
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
13-
account_id=$(cat config/API_ACCOUNT_ID)
14-
workflow_id=$(cat config/WORKFLOW_ID)
15-
16-
# Step 2: Validate workflow ID exists
17-
if [ -z "$workflow_id" ]; then
18-
echo "No workflow ID found. Please run the trigger workflow script first."
19-
exit 1
10+
# Step 1: Check that the workflow ID exists
11+
workflow_created=$(cat config/WORKFLOW_ID)
12+
if [ -z "$workflow_created" ]; then
13+
bash ./examples/Maestro/utils.sh
2014
fi
2115

22-
# Step 3: Set Maestro API base path
23-
base_path="https://api-d.docusign.net/maestro/v1"
24-
25-
# Step 4: Prepare API headers
26-
declare -a Headers=(
27-
'--header' "Authorization: Bearer ${ACCESS_TOKEN}"
28-
'--header' "Content-Type: application/json"
29-
'--header' "Accept: application/json"
30-
)
31-
32-
# Step 5: Prepare POST body with returnUrl
33-
request_data=$(mktemp /tmp/request-embed.XXXXXX)
34-
printf \
35-
'{
36-
"returnUrl": "https://example.com/return"
37-
}' > $request_data
38-
39-
# Step 6: Make API call to get embed URL
40-
response=$(mktemp /tmp/response-embed.XXXXXX)
41-
Status=$(curl -s -w "%{http_code}\n" -i --request POST \
42-
"${base_path}/accounts/${account_id}/workflows/${workflow_id}/embed_url" \
43-
"${Headers[@]}" \
44-
--data-binary @$request_data \
45-
--output ${response})
16+
#check that create workflow script ran successfully
17+
workflow_created=$(cat config/WORKFLOW_ID)
18+
if [ -z "$workflow_created" ]; then
19+
echo "please create a worklow before running this example"
20+
exit 0
21+
fi
4622

47-
# Step 7: Handle errors
48-
if [[ "$Status" -gt "201" ]]; then
49-
echo "Failed to generate embed URL"
50-
cat $response
51-
rm "$request_data" "$response"
52-
exit 1
23+
# Step 2: Check that the instance URL exists
24+
instance_url=$(grep '"instance_url":' $response | sed -n 's/.*"instance_url": "\([^"]*\)".*/\1/p')
25+
if [ -z "$instance_url" ]; then
26+
echo "No instance URL found. Please run the trigger workflow script first."
27+
exit 1
5328
fi
5429

55-
# Step 8: Extract and display embed URL
56-
embed_url=$(grep '"url":' $response | sed -n 's/.*"url": "\([^"]*\)".*/\1/p')
30+
# Step 3: Decode any escaped characters
31+
decoded_instance_url=$(echo "$instance_url" | sed 's/\\u0026/\&/g')
5732

33+
# Step 4: Output for developer
5834
echo ""
59-
echo "Embed URL successfully generated:"
60-
echo "$embed_url"
61-
35+
echo "✅ Workflow instance URL retrieved for workflow ID: $workflow_id"
6236
echo ""
63-
echo "📎 You can use this HTML iframe to embed the workflow:"
64-
echo "<iframe src=\"$embed_url\" width=\"100%\" height=\"600\" frameborder=\"0\" allowfullscreen></iframe>"
65-
66-
# Cleanup
67-
rm "$request_data" "$response"
37+
echo "🔗 URL:"
38+
echo "$decoded_instance_url"
39+
echo ""
40+
echo "📎 Use this HTML snippet to embed the workflow in your application:"
41+
echo ""
42+
echo "<div class=\"formContainer\">"
43+
echo " <iframe src=\"$decoded_instance_url\" width=\"800\" height=\"600\"></iframe>"
44+
echo "</div>"

0 commit comments

Comments
 (0)