Skip to content

Commit af273dc

Browse files
author
Raileen Del Rosario
committed
DEVDOCS-16285 - adding connected fields example
1 parent bf388ab commit af273dc

File tree

3 files changed

+272
-3
lines changed

3 files changed

+272
-3
lines changed

OAuth/code_grant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$api_version = "$argv[1]";
1313

1414
if($api_version == "eSignature" || $api_version == "idEvidence") :
15-
$scope = 'signature';
15+
$scope = 'signature adm_store_unified_repo_read';
1616
elseif($api_version == "Rooms") :
1717
$scope = 'dtr.rooms.read dtr.rooms.write dtr.documents.read dtr.documents.write dtr.profile.read dtr.profile.write dtr.company.read dtr.company.write room_forms';
1818
elseif($api_version == "Click") :
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
# Check that we're in a bash shell
2+
if [[ $SHELL != *"bash"* ]]; then
3+
echo "PROBLEM: Run these scripts from within the bash shell."
4+
fi
5+
6+
if ! command -v jq &> /dev/null; then
7+
echo "jq is not installed. Installing jq..."
8+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
9+
sudo apt-get update && sudo apt-get install -y jq # For Debian/Ubuntu
10+
elif [[ "$OSTYPE" == "darwin"* ]]; then
11+
brew install jq # For macOS (Homebrew)
12+
elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]]; then
13+
echo "Please install jq manually from: https://stedolan.github.io/jq/download/"
14+
exit 1
15+
else
16+
echo "Unsupported OS. Please install jq manually."
17+
exit 1
18+
fi
19+
else
20+
echo "jq is already installed."
21+
fi
22+
23+
ds_access_token_path="config/ds_access_token.txt"
24+
verification_file="config/verification_app.txt"
25+
26+
# Obtain your OAuth token
27+
# Note: Substitute these values with your own
28+
ACCESS_TOKEN=$(cat ${ds_access_token_path})
29+
30+
# Set up variables for full code example
31+
# Note: Substitute these values with your own
32+
account_id=$(cat config/API_ACCOUNT_ID)
33+
base_path="https://api-d.docusign.com/v1"
34+
35+
#ds-snippet-start:Navigator1Step2
36+
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
37+
'--header' "Accept: application/json" \
38+
'--header' "Content-Type: application/json")
39+
#ds-snippet-end:Navigator1Step2
40+
41+
# List agreements
42+
#ds-snippet-start:Navigator1Step3
43+
response=$(mktemp /tmp/response-cf.XXXXXX)
44+
Status=$(curl -w '%{http_code}' -i --ssl-no-revoke --request GET https://api-d.docusign.com/v1/accounts/${account_id}/connected-fields/tab-groups \
45+
"${Headers[@]}" \
46+
--output ${response})
47+
#ds-snippet-end:Navigator1Step3
48+
49+
echo ""
50+
echo "Response:"
51+
cat $response
52+
echo ""
53+
54+
extract_verify_info() {
55+
clean_response=$(sed -n '/\[/,$p' "$response")
56+
echo "$clean_response" | jq '[.[] | select(.tabs[]?.extensionData.actionContract | contains("Verify"))]'
57+
}
58+
59+
prompt_user_choice() {
60+
local json_data="$1"
61+
local apps=( $(echo "$json_data" | jq -r '.[] | .appId') )
62+
mapfile -t names < <(echo "$json_data" | jq -r '.[] | .tabs[0].extensionData.applicationName')
63+
64+
65+
if [[ -z "$json_data" || "$json_data" == "[]" ]]; then
66+
echo "Error: No verification apps found in the data."
67+
exit 1
68+
fi
69+
70+
echo "Please select an app by entering a number:"
71+
for i in "${!names[@]}"; do
72+
echo "$((i+1)). ${names[$i]}"
73+
done
74+
75+
read -p "Enter choice (1-${#names[@]}): " choice
76+
if [[ "$choice" =~ ^[1-${#names[@]}]$ ]]; then
77+
chosen_app_id="${apps[$((choice-1))]}"
78+
selected_data=$(echo "$json_data" | jq --arg appId "$chosen_app_id" '[.[] | select(.appId == $appId)]')
79+
parse_verification_data "$selected_data"
80+
else
81+
echo "Invalid choice. Exiting."
82+
exit 1
83+
fi
84+
}
85+
86+
parse_verification_data() {
87+
local clean_json="$1"
88+
89+
app_id=$(echo "$clean_json" | jq -r '.[0].appId')
90+
extension_group_id=$(echo "$clean_json" | jq -r '.[0].tabs[0].extensionData.extensionGroupId')
91+
publisher_name=$(echo "$clean_json" | jq -r '.[0].tabs[0].extensionData.publisherName')
92+
application_name=$(echo "$clean_json" | jq -r '.[0].tabs[0].extensionData.applicationName')
93+
action_name=$(echo "$clean_json" | jq -r '.[0].tabs[0].extensionData.actionName')
94+
action_contract=$(echo "$clean_json" | jq -r '.[0].tabs[0].extensionData.actionContract')
95+
extension_name=$(echo "$clean_json" | jq -r '.[0].tabs[0].extensionData.extensionName')
96+
extension_contract=$(echo "$clean_json" | jq -r '.[0].tabs[0].extensionData.extensionContract')
97+
required_for_extension=$(echo "$clean_json" | jq -r '.[0].tabs[0].extensionData.requiredForExtension')
98+
validation_pattern=$(echo "$clean_json" | jq -r '.[0].tabs[]? | select(.extensionData.actionInputKey=="phoneNumber").validationPattern')
99+
tab_label=$(echo "$clean_json" | jq -r '.[0].tabs[]? | select(.extensionData.actionInputKey=="phoneNumber").tabLabel')
100+
connection_key=$(echo "$clean_json" | jq -r '.[0].tabs[0].extensionData.connectionInstances[0].connectionKey')
101+
connection_value=$(echo "$clean_json" | jq -r '.[0].tabs[0].extensionData.connectionInstances[0].connectionValue')
102+
103+
echo "App ID: $app_id"
104+
echo "Extension Group ID: $extension_group_id"
105+
echo "Publisher Name: $publisher_name"
106+
echo "Application Name: $application_name"
107+
echo "Action Name: $action_name"
108+
echo "Action Contract: $action_contract"
109+
echo "Extension Name: $extension_name"
110+
echo "Extension Contract: $extension_contract"
111+
echo "Required for Extension: $required_for_extension"
112+
echo "Validation Pattern: $validation_pattern"
113+
echo "Tab Label: $tab_label"
114+
echo "Connection Key: $connection_key"
115+
echo "Connection Value: $connection_value"
116+
}
117+
118+
if [[ -z "$response" ]]; then
119+
echo "Error: response file variable not set."
120+
exit 1
121+
fi
122+
123+
filtered_data=$(extract_verify_info)
124+
125+
if [[ -z "$filtered_data" || "$filtered_data" == "[]" ]]; then
126+
echo "Error: No verification data found in response file."
127+
exit 1
128+
fi
129+
130+
prompt_user_choice "$filtered_data"
131+
132+
request_data=$(mktemp /tmp/request-eg-045.XXXXXX)
133+
doc1_base64=$(mktemp /tmp/eg-045-doc1.XXXXXX)
134+
cat demo_documents/World_Wide_Corp_lorem.pdf | base64 > $doc1_base64
135+
136+
printf \
137+
'{
138+
"emailSubject": "Please sign this document",
139+
"documents": [
140+
{
141+
"documentBase64": "' > "$request_data"
142+
cat $doc1_base64 >> $request_data
143+
printf '",
144+
"name": "Lorem Ipsum",
145+
"fileExtension": "pdf",
146+
"documentId": "1"
147+
}
148+
],
149+
"status": "sent",
150+
"recipients": {
151+
"signers": [
152+
{
153+
"email": "'"${SIGNER_EMAIL}"'",
154+
"name": "'"${SIGNER_NAME}"'",
155+
"recipientId": "1",
156+
"routingOrder": "1",
157+
"tabs": {
158+
"signHereTabs": [
159+
{
160+
"anchorString": "/sn1/",
161+
"anchorUnits": "pixels",
162+
"anchorXOffset": "20",
163+
"anchorYOffset": "10"
164+
}
165+
],
166+
"textTabs": [
167+
{
168+
"validationPattern": "'"${validation_pattern}"'",
169+
"validationMessage": "'"${validation_message}"'",
170+
"requireInitialOnSharedChange": false,
171+
"requireAll": false,
172+
"name": "'"${name}"'",
173+
"value": "",
174+
"required": true,
175+
"locked": false,
176+
"disableAutoSize": false,
177+
"maxLength": 4000,
178+
"tabLabel": "'"${tab_label}"'",
179+
"font": "lucidaconsole",
180+
"fontColor": "black",
181+
"fontSize": "size9",
182+
"documentId": "1",
183+
"recipientId": "1",
184+
"pageNumber": "1",
185+
"xPosition": "273",
186+
"yPosition": "191",
187+
"width": "84",
188+
"height": "22",
189+
"tabId": "'"${tab_id}"'",
190+
"templateRequired": false,
191+
"tabType": "text",
192+
"tooltip": "Phone Number",
193+
"extensionData": {
194+
"extensionGroupId": "'"${extension_group_id}"'",
195+
"publisherName": "'"${publisher_name}"'",
196+
"applicationId": "'"${application_id}"'",
197+
"applicationName": "'"${application_name}"'",
198+
"actionName": "'"${action_name}"'",
199+
"actionContract": "'"${action_contract}"'",
200+
"extensionName": "'"${extension_name}"'",
201+
"extensionContract": "'"${extension_contract}"'",
202+
"requiredForExtension": "'"${required_for_extension}"'",
203+
"actionInputKey": "phoneNumber",
204+
"extensionPolicy": "None",
205+
"connectionInstances": [
206+
{
207+
"connectionKey": "'"${connection_key}"'",
208+
"connectionValue": "'"${connection_value}"'"
209+
}
210+
]
211+
}
212+
}
213+
]
214+
}
215+
}
216+
]
217+
}
218+
}' >> $request_data
219+
220+
# Remove the temporary file
221+
rm "$response"
222+
223+
echo ""
224+
echo ""
225+
echo "Done."
226+
echo ""
227+
228+
response=$(mktemp /tmp/response-eg-045.XXXXXX)
229+
230+
echo ""
231+
echo "Sending the envelope request to Docusign..."
232+
233+
234+
base_path2="https://demo.docusign.net/restapi"
235+
236+
#ds-snippet-start:eSign2Step3
237+
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
238+
--header "Content-Type: application/json" \
239+
--data-binary @${request_data} \
240+
--request POST ${base_path2}/v2.1/accounts/${account_id}/envelopes \
241+
--output $response
242+
#ds-snippet-end:eSign2Step3
243+
244+
echo ""
245+
echo "Response:"
246+
cat $response
247+
echo ""
248+
249+
# pull out the envelopeId
250+
envelope_id=`cat $response | grep envelopeId | sed 's/.*\"envelopeId\":\"//' | sed 's/\",.*//'`
251+
252+
# Save the envelope id for use by other scripts
253+
echo "EnvelopeId: ${envelope_id}"
254+
echo ${envelope_id} > config/ENVELOPE_ID
255+
256+
# cleanup
257+
rm "$request_data"
258+
rm "$response"
259+
rm "$doc1_base64"
260+
261+
echo ""
262+
echo ""
263+
echo "Done. When signing the envelope, ensure the connection to your data verification extension app is active."
264+
echo ""

launcher.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ function startSignature() {
294294
"Shared_Access" \
295295
"Document_Generation" \
296296
"Focused_View" \
297+
"Connected_Fields" \
297298
"Pick_An_API"; do
298299
case "$CHOICE" in
299300
Pick_An_API)
@@ -467,6 +468,10 @@ function startSignature() {
467468
bash examples/eSignature/eg044FocusedView.sh
468469
startSignature
469470
;;
471+
Connected_Fields)
472+
bash examples/eSignature/eg045ConnectedFields.sh
473+
startSignature
474+
;;
470475
*)
471476
echo ""
472477
startSignature
@@ -1046,6 +1051,6 @@ function continu() {
10461051
}
10471052

10481053
echo ""
1049-
echo "Welcome to the DocuSign Bash Launcher"
1054+
echo "Welcome to the Docusign Bash Launcher"
10501055

1051-
choices
1056+
choices

0 commit comments

Comments
 (0)