|
1 | 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 |
| 2 | +# Embed a Maestro workflow instance using the URL returned from triggerWorkflow |
4 | 3 |
|
5 | | -# Ensure bash shell |
| 4 | +# Ensure the script is run in a bash shell |
6 | 5 | if [[ $SHELL != *"bash"* ]]; then |
7 | 6 | echo "PROBLEM: Run these scripts from within the bash shell." |
8 | 7 | exit 1 |
9 | 8 | fi |
10 | 9 |
|
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 |
20 | 14 | fi |
21 | 15 |
|
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 |
46 | 22 |
|
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 |
53 | 28 | fi |
54 | 29 |
|
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') |
57 | 32 |
|
| 33 | +# Step 4: Output for developer |
58 | 34 | echo "" |
59 | | -echo "Embed URL successfully generated:" |
60 | | -echo "$embed_url" |
61 | | - |
| 35 | +echo "✅ Workflow instance URL retrieved for workflow ID: $workflow_id" |
62 | 36 | 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