|
1 | | -# #!/bin/bash |
2 | | -# # https://developers.docusign.com/docs/maestro-api/maestro101/embed-workflow/ |
3 | | -# # Embed a Maestro workflow after it has been triggered |
| 1 | +#!/bin/bash |
| 2 | +# https://developers.docusign.com/docs/maestro-api/maestro101/embed-workflow/ |
| 3 | +# Generates an embeddable Maestro workflow URL using the workflow ID |
4 | 4 |
|
5 | | -# # Check that we're in a bash shell |
6 | | -# if [[ $SHELL != *"bash"* ]]; then |
7 | | -# echo "PROBLEM: Run these scripts from within the bash shell." |
8 | | -# fi |
| 5 | +# Ensure bash shell |
| 6 | +if [[ $SHELL != *"bash"* ]]; then |
| 7 | + echo "PROBLEM: Run these scripts from within the bash shell." |
| 8 | + exit 1 |
| 9 | +fi |
9 | 10 |
|
10 | | -# # Step 1: Obtain your OAuth token |
11 | | -# ACCESS_TOKEN=$(cat config/ds_access_token.txt) |
| 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) |
12 | 15 |
|
13 | | -# # Step 2: Read the account ID |
14 | | -# account_id=$(cat config/API_ACCOUNT_ID) |
| 16 | +# Step 2: Validate workflow ID exists |
| 17 | +if [ -z "$workflow_id" ]; then |
| 18 | + echo "❌ ERROR: No workflow ID found. Please run the trigger workflow script first." |
| 19 | + exit 1 |
| 20 | +fi |
15 | 21 |
|
16 | | -# # Step 3: Read the workflow ID created by the trigger workflow script |
17 | | -# workflow_id=$(cat config/WORKFLOW_ID) |
| 22 | +# Step 3: Set Maestro API base path |
| 23 | +base_path="https://api-d.docusign.net/maestro/v1" |
18 | 24 |
|
19 | | -# # Step 4: Verify a workflow has been created |
20 | | -# if [ -z "$workflow_id" ]; then |
21 | | -# echo "❌ ERROR: No workflow found. Please trigger a workflow before running this embed script." |
22 | | -# exit 0 |
23 | | -# fi |
| 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 | +) |
24 | 31 |
|
25 | | -# # Step 5: Construct your API headers |
26 | | -# declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ |
27 | | -# '--header' "Accept: application/json" \ |
28 | | -# '--header' "Content-Type: application/json") |
| 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 |
29 | 38 |
|
30 | | -# # Step 6: Prepare request body |
31 | | -# request_data=$(mktemp /tmp/request-embed.XXXXXX) |
32 | | -# printf \ |
33 | | -# '{ |
34 | | -# "returnUrl": "https://example.com/return" |
35 | | -# }' > $request_data |
| 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}) |
36 | 46 |
|
37 | | -# # Step 7: Make the POST request to generate the embed URL |
38 | | -# response=$(mktemp /tmp/response-embed.XXXXXX) |
39 | | -# Status=$(curl -s -w "%{http_code}\n" -i --request POST "https://api-d.docusign.net/maestro/v1/accounts/${account_id}/workflows/${workflow_id}/embed_url" \ |
40 | | -# "${Headers[@]}" \ |
41 | | -# --data-binary @$request_data \ |
42 | | -# --output ${response}) |
| 47 | +# Step 7: Handle errors |
| 48 | +if [[ "$Status" -gt "201" ]]; then |
| 49 | + echo "❌ ERROR: Failed to generate embed URL" |
| 50 | + cat $response |
| 51 | + rm "$request_data" "$response" |
| 52 | + exit 1 |
| 53 | +fi |
43 | 54 |
|
44 | | -# # Step 8: Handle the response |
45 | | -# if [[ "$Status" -gt "201" ]]; then |
46 | | -# echo "" |
47 | | -# echo "❌ ERROR: Unable to generate embed URL for the workflow" |
48 | | -# echo "" |
49 | | -# cat $response |
50 | | -# rm "$request_data" |
51 | | -# rm "$response" |
52 | | -# exit 0 |
53 | | -# fi |
| 55 | +# Step 8: Extract and display embed URL |
| 56 | +embed_url=$(grep '"url":' $response | sed -n 's/.*"url": "\([^"]*\)".*/\1/p') |
54 | 57 |
|
55 | | -# echo "" |
56 | | -# echo "✅ Embed URL successfully generated:" |
57 | | -# embed_url=$(grep '"url":' $response | sed -n 's/.*"url": "\([^"]*\)".*/\1/p') |
58 | | -# echo $embed_url |
| 58 | +echo "" |
| 59 | +echo "✅ Embed URL successfully generated:" |
| 60 | +echo "$embed_url" |
59 | 61 |
|
60 | | -# # Optional: Output embed code for iframe usage |
61 | | -# echo "" |
62 | | -# echo "📎 Use this in your HTML:" |
63 | | -# echo "<iframe src=\"$embed_url\" width=\"100%\" height=\"600\" frameborder=\"0\" allowfullscreen></iframe>" |
| 62 | +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>" |
64 | 65 |
|
65 | | -# # Clean up |
66 | | -# rm "$request_data" |
67 | | -# rm "$response" |
| 66 | +# Cleanup |
| 67 | +rm "$request_data" "$response" |
0 commit comments