Skip to content

Commit 57585e2

Browse files
committed
more eg
1 parent 1ebfab6 commit 57585e2

File tree

5 files changed

+586
-0
lines changed

5 files changed

+586
-0
lines changed

examples/eg009UseTemplate.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Send a signing request via email using a DocuSign template
2+
3+
# Configuration
4+
# 1. Search for and update '{USER_EMAIL}' and '{USER_FULLNAME}'.
5+
# They occur and re-occur multiple times below.
6+
# 2. Obtain an OAuth access token from
7+
# https://developers.hqtest.tst/oauth-token-generator
8+
access_token='{ACCESS_TOKEN}'
9+
# 3. Obtain your accountId from demo.docusign.com -- the account id is shown in
10+
# the drop down on the upper right corner of the screen by your picture or
11+
# the default picture.
12+
account_id='{ACCOUNT_ID}'
13+
14+
# Check that we're in a bash shell
15+
if [[ $SHELL != *"bash"* ]]; then
16+
echo "PROBLEM: Run these scripts from within the bash shell."
17+
fi
18+
# Check that we have a template id
19+
if [ ! -f ../TEMPLATE_ID ]; then
20+
echo ""
21+
echo "PROBLEM: An template id is needed. Fix: execute script eg008CreateTemplate.sh"
22+
echo ""
23+
exit -1
24+
fi
25+
template_id=`cat ../TEMPLATE_ID`
26+
27+
#
28+
# Step 1. Create the envelope request.
29+
base_path="https://demo.docusign.net/restapi"
30+
# temp files:
31+
response=$(mktemp /tmp/response-eg-009.XXXXXX)
32+
33+
echo ""
34+
echo "Sending the envelope request to DocuSign..."
35+
36+
curl --header "Authorization: Bearer ${access_token}" \
37+
--header "Content-Type: application/json" \
38+
--data-binary \
39+
"{
40+
\"templateId\": \"8daaae89-e16d-47b8-929a-d6b8b59e1ba8\",
41+
\"templateRoles\": [
42+
{
43+
\"email\": \"{USER_EMAIL}\",
44+
\"name\": \"{USER_FULLNAME}\",
45+
\"roleName\": \"signer\"
46+
},
47+
{
48+
\"email\": \"{USER_EMAIL}\",
49+
\"name\": \"Charlie Copy\",
50+
\"roleName\": \"cc\"
51+
}
52+
],
53+
\"status\": \"sent\"
54+
}" \
55+
--request POST ${base_path}/v2/accounts/${account_id}/envelopes \
56+
--output ${response}
57+
58+
echo ""
59+
echo "Response:"
60+
cat $response
61+
rm $response
62+
echo ""
63+
echo ""
64+
echo "Done."
65+
echo ""
66+
67+

examples/eg011EmbeddedSending.sh

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# Embedded Sending:
2+
# 1. create a draft envelope with three documents
3+
# 2. Open the sending view of the DocuSign web tool
4+
#
5+
6+
# Configuration
7+
# 1. Search for and update '{USER_EMAIL}' and '{USER_FULLNAME}'.
8+
# They occur and re-occur multiple times below.
9+
# 2. Obtain an OAuth access token from
10+
# https://developers.hqtest.tst/oauth-token-generator
11+
access_token='{ACCESS_TOKEN}'
12+
# 3. Obtain your accountId from demo.docusign.com -- the account id is shown in
13+
# the drop down on the upper right corner of the screen by your picture or
14+
# the default picture.
15+
account_id='{ACCOUNT_ID}'
16+
17+
# Check that we're in a bash shell
18+
if [[ $SHELL != *"bash"* ]]; then
19+
echo "PROBLEM: Run these scripts from within the bash shell."
20+
fi
21+
base_path="https://demo.docusign.net/restapi"
22+
23+
# The sending editor can be opened in either of two views:
24+
echo ""
25+
PS3='Select the initial sending view: '
26+
options=("Tagging view" "Recipients and documents view")
27+
select opt in "${options[@]}"
28+
do
29+
case $opt in
30+
"Tagging view")
31+
starting_view=tagging
32+
break
33+
;;
34+
"Recipients and documents view")
35+
starting_view=recipient
36+
break
37+
;;
38+
esac
39+
done
40+
41+
# Create the document request body
42+
# document 1 (html) has tag **signature_1**
43+
# document 2 (docx) has tag /sn1/
44+
# document 3 (pdf) has tag /sn1/
45+
#
46+
# The envelope has two recipients.
47+
# recipient 1 - signer
48+
# recipient 2 - cc
49+
# The envelope will be sent first to the signer.
50+
# After it is signed, a copy is sent to the cc person.
51+
52+
# temp files:
53+
request_data=$(mktemp /tmp/request-eg-002.XXXXXX)
54+
response=$(mktemp /tmp/response-eg-002.XXXXXX)
55+
doc1_base64=$(mktemp /tmp/eg-002-doc1.XXXXXX)
56+
doc2_base64=$(mktemp /tmp/eg-002-doc2.XXXXXX)
57+
doc3_base64=$(mktemp /tmp/eg-002-doc3.XXXXXX)
58+
59+
# Fetch docs and encode
60+
cat ../demo_documents/doc_1.html | base64 > $doc1_base64
61+
cat ../demo_documents/World_Wide_Corp_Battle_Plan_Trafalgar.docx | base64 > $doc2_base64
62+
cat ../demo_documents/World_Wide_Corp_lorem.pdf | base64 > $doc3_base64
63+
64+
echo ""
65+
echo "Sending the envelope request to DocuSign..."
66+
echo "The envelope has three documents. Processing time will be about 15 seconds."
67+
echo "Results:"
68+
echo ""
69+
70+
# Concatenate the different parts of the request
71+
printf \
72+
'{
73+
"emailSubject": "Please sign this document set",
74+
"documents": [
75+
{
76+
"documentBase64": "' > $request_data
77+
cat $doc1_base64 >> $request_data
78+
printf '",
79+
"name": "Order acknowledgement",
80+
"fileExtension": "html",
81+
"documentId": "1"
82+
},
83+
{
84+
"documentBase64": "' >> $request_data
85+
cat $doc2_base64 >> $request_data
86+
printf '",
87+
"name": "Battle Plan",
88+
"fileExtension": "docx",
89+
"documentId": "2"
90+
},
91+
{
92+
"documentBase64": "' >> $request_data
93+
cat $doc3_base64 >> $request_data
94+
printf '",
95+
"name": "Lorem Ipsum",
96+
"fileExtension": "pdf",
97+
"documentId": "3"
98+
}
99+
],
100+
"recipients": {
101+
"carbonCopies": [
102+
{
103+
"email": "{USER_EMAIL}",
104+
"name": "Charles Copy",
105+
"recipientId": "2",
106+
"routingOrder": "2"
107+
}
108+
],
109+
"signers": [
110+
{
111+
"email": "{USER_EMAIL}",
112+
"name": "{USER_FULLNAME}",
113+
"recipientId": "1",
114+
"routingOrder": "1",
115+
"tabs": {
116+
"signHereTabs": [
117+
{
118+
"anchorString": "**signature_1**",
119+
"anchorUnits": "pixels",
120+
"anchorXOffset": "20",
121+
"anchorYOffset": "10"
122+
},
123+
{
124+
"anchorString": "/sn1/",
125+
"anchorUnits": "pixels",
126+
"anchorXOffset": "20",
127+
"anchorYOffset": "10"
128+
}
129+
]
130+
}
131+
}
132+
]
133+
},
134+
"status": "draft"
135+
}' >> $request_data
136+
137+
curl --header "Authorization: Bearer ${access_token}" \
138+
--header "Content-Type: application/json" \
139+
--data-binary @${request_data} \
140+
--request POST ${base_path}/v2/accounts/${account_id}/envelopes \
141+
--output $response
142+
143+
echo ""
144+
cat $response
145+
146+
# pull out the envelopeId
147+
envelope_id=`cat $response | grep envelopeId | sed 's/.*\"envelopeId\": \"//' | sed 's/\",.*//'`
148+
149+
echo ""
150+
echo "Requesting the sender view url"
151+
152+
# The returnUrl is normally your own web app. DocuSign will redirect
153+
# the signer to returnUrl when the sending ceremony completes.
154+
# For this example, we'll use http://httpbin.org/get to show the
155+
# query parameters passed back from DocuSign
156+
curl --header "Authorization: Bearer ${access_token}" \
157+
--header "Content-Type: application/json" \
158+
--data-binary "{\"returnUrl\": \"http://httpbin.org/get\"}" \
159+
--request POST ${base_path}/v2/accounts/${account_id}/envelopes/${envelope_id}/views/sender \
160+
--output $response
161+
162+
echo ""
163+
cat $response
164+
sending_ceremony_url=`cat $response | grep url | sed 's/.*\"url\": \"//' | sed 's/\".*//'`
165+
# Next, we update the returned url if we want to start with the Recipient
166+
# and Documents view
167+
if [ "$starting_view" = "recipient" ]; then
168+
sending_ceremony_url=`printf "${sending_ceremony/send=1/send=0}"`
169+
fi
170+
171+
echo ""
172+
printf "The sending ceremony URL is ${sending_ceremony_url}\n"
173+
printf "It is only valid for a couple of minutes. Attempting to automatically open your browser...\n"
174+
if which xdg-open &> /dev/null ; then
175+
xdg-open "$sending_ceremony_url"
176+
elif which open &> /dev/null ; then
177+
open "$sending_ceremony_url"
178+
elif which start &> /dev/null ; then
179+
start "$sending_ceremony_url"
180+
fi
181+
182+
# cleanup
183+
rm "$request_data"
184+
rm "$response"
185+
rm "$doc1_base64"
186+
rm "$doc2_base64"
187+
rm "$doc3_base64"
188+
189+
echo ""
190+
echo ""
191+
echo "Done."
192+
echo ""
193+

examples/eg012EmbeddedConsole.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# List envelopes and their status
2+
# List changes for the last 10 days
3+
4+
# Check that we're in a bash shell
5+
if [[ $SHELL != *"bash"* ]]; then
6+
echo "PROBLEM: Run these scripts from within the bash shell."
7+
fi
8+
base_path="https://demo.docusign.net/restapi"
9+
10+
# Configuration
11+
# 1. Obtain an OAuth access token from
12+
# https://developers.hqtest.tst/oauth-token-generator
13+
access_token='{ACCESS_TOKEN}'
14+
# 2. Obtain your accountId from demo.docusign.com -- the account id is shown in
15+
# the drop down on the upper right corner of the screen by your picture or
16+
# the default picture.
17+
account_id='{ACCOUNT_ID}'
18+
19+
echo ""
20+
echo "Sending the list envelope status request to DocuSign..."
21+
echo "Results:"
22+
echo ""
23+
24+
# Calculate the from_date query parameter and use the ISO 8601 format.
25+
# Example:
26+
# from_date=2018-09-30T07:43:12+03:00
27+
# For a Mac, 10 days in the past:
28+
if date -v -10d &> /dev/null ; then
29+
# Mac
30+
from_date=`date -v -10d '+%Y-%m-%dT%H:%M:%S%z'`
31+
else
32+
# Not a Mac
33+
from_date=`date --date='-10 days' '+%Y-%m-%dT%H:%M:%S%z'`
34+
fi
35+
36+
curl --header "Authorization: Bearer ${access_token}" \
37+
--header "Content-Type: application/json" \
38+
--get \
39+
--data-urlencode "from_date=${from_date}" \
40+
--request GET ${base_path}/v2/accounts/${account_id}/envelopes
41+
42+
echo ""
43+
echo ""
44+
echo "Done."
45+
echo ""
46+

0 commit comments

Comments
 (0)