Skip to content

Commit 35a0566

Browse files
committed
eg007
1 parent 9148ea5 commit 35a0566

File tree

2 files changed

+192
-0
lines changed

2 files changed

+192
-0
lines changed

Examples/eg007EnvelopeGetDoc.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Download a document from an envelope
2+
# This script uses the envelope_id stored in ../ENVELOPE_ID.
3+
# The ENVELOPE_ID file is created by example eg002SigningViaEmail.sh or
4+
# can be manually created.
5+
6+
output_file="envelope_document."
7+
# Check that we're in a bash shell
8+
if [[ $SHELL != *"bash"* ]]; then
9+
echo "PROBLEM: Run these scripts from within the bash shell."
10+
fi
11+
12+
# Check that we have an envelope id
13+
if [ ! -f ../ENVELOPE_ID ]; then
14+
echo ""
15+
echo "PROBLEM: An envelope id is needed. Fix: execute script eg002SigningViaEmail.sh"
16+
echo ""
17+
exit -1
18+
fi
19+
envelope_id=`cat ../ENVELOPE_ID`
20+
21+
doc_choice=1
22+
output_file_extension=pdf
23+
PS3='Select a document or document set to download: '
24+
options=("Documents combined together" "ZIP file" "Document 1" "Document 2" "Document 3")
25+
select opt in "${options[@]}"
26+
do
27+
case $opt in
28+
"Documents combined together")
29+
doc_choice=combined
30+
;;
31+
"ZIP file")
32+
doc_choice=archive
33+
output_file_extension=zip
34+
;;
35+
"Document 1")
36+
doc_choice=1
37+
;;
38+
"Document 2")
39+
doc_choice=2
40+
;;
41+
"Document 3")
42+
doc_choice=3
43+
;;
44+
esac
45+
done
46+
47+
echo ""
48+
echo "Sending the EnvelopeDocuments::get request to DocuSign..."
49+
echo "The document(s) are stored in file ${output_file}${output_file_extension}"
50+
echo ""
51+
52+
curl --header "Authorization: Bearer {ACCESS_TOKEN}" \
53+
--header "Content-Type: application/json" \
54+
--request GET https://demo.docusign.net/restapi/v2/accounts/{ACCOUNT_ID}/envelopes/${envelope_id}/documents/${doc_choice} \
55+
--output ${output_file}${output_file_extension}
56+
57+
echo ""
58+
echo ""
59+
echo "Done."
60+
echo ""
61+

Examples/eg008CreateTemplate.sh

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Send an envelope with three documents
2+
#
3+
# Check that we're in a bash shell
4+
if [[ $SHELL != *"bash"* ]]; then
5+
echo "PROBLEM: Run these scripts from within the bash shell."
6+
fi
7+
8+
# document 1 (html) has tag **signature_1**
9+
# document 2 (docx) has tag /sn1/
10+
# document 3 (pdf) has tag /sn1/
11+
#
12+
# The envelope has two recipients.
13+
# recipient 1 - signer
14+
# recipient 2 - cc
15+
# The envelope will be sent first to the signer.
16+
# After it is signed, a copy is sent to the cc person.
17+
18+
# temp files:
19+
request_data=$(mktemp /tmp/request-eg-002.XXXXXX)
20+
response=$(mktemp /tmp/response-eg-002.XXXXXX)
21+
doc1_base64=$(mktemp /tmp/eg-002-doc1.XXXXXX)
22+
doc2_base64=$(mktemp /tmp/eg-002-doc2.XXXXXX)
23+
doc3_base64=$(mktemp /tmp/eg-002-doc3.XXXXXX)
24+
25+
# Fetch docs and encode
26+
cat ../demo_documents/doc_1.html | base64 > $doc1_base64
27+
cat ../demo_documents/World_Wide_Corp_Battle_Plan_Trafalgar.docx | base64 > $doc2_base64
28+
cat ../demo_documents/World_Wide_Corp_lorem.pdf | base64 > $doc3_base64
29+
30+
echo ""
31+
echo "Sending the envelope request to DocuSign..."
32+
echo "The envelope has three documents. Processing time will be about 15 seconds."
33+
echo "Results:"
34+
echo ""
35+
36+
# Concatenate the different parts of the request
37+
printf \
38+
'{
39+
"emailSubject": "Please sign this document set",
40+
"documents": [
41+
{
42+
"documentBase64": "' > $request_data
43+
cat $doc1_base64 >> $request_data
44+
printf \
45+
'",
46+
"name": "Order acknowledgement",
47+
"fileExtension": "html",
48+
"documentId": "1"
49+
},
50+
{
51+
"documentBase64": "' >> $request_data
52+
cat $doc2_base64 >> $request_data
53+
printf \
54+
'",
55+
"name": "Battle Plan",
56+
"fileExtension": "docx",
57+
"documentId": "2"
58+
},
59+
{
60+
"documentBase64": "' >> $request_data
61+
cat $doc3_base64 >> $request_data
62+
printf \
63+
'",
64+
"name": "Lorem Ipsum",
65+
"fileExtension": "pdf",
66+
"documentId": "3"
67+
}
68+
],
69+
"recipients": {
70+
"carbonCopies": [
71+
{
72+
"email": "{USER_EMAIL}",
73+
"name": "Charles Copy",
74+
"recipientId": "2",
75+
"routingOrder": "2"
76+
}
77+
],
78+
"signers": [
79+
{
80+
"email": "{USER_EMAIL}",
81+
"name": "{USER_FULLNAME}",
82+
"recipientId": "1",
83+
"routingOrder": "1",
84+
"tabs": {
85+
"signHereTabs": [
86+
{
87+
"anchorString": "**signature_1**",
88+
"anchorUnits": "pixels",
89+
"anchorXOffset": "20",
90+
"anchorYOffset": "10"
91+
},
92+
{
93+
"anchorString": "/sn1/",
94+
"anchorUnits": "pixels",
95+
"anchorXOffset": "20",
96+
"anchorYOffset": "10"
97+
}
98+
]
99+
}
100+
}
101+
]
102+
},
103+
"status": "sent"
104+
}' >> $request_data
105+
106+
curl --header "Authorization: Bearer {ACCESS_TOKEN}" \
107+
--header "Content-Type: application/json" \
108+
--data-binary @${request_data} \
109+
--request POST https://demo.docusign.net/restapi/v2/accounts/{ACCOUNT_ID}/envelopes \
110+
--output $response
111+
112+
echo ""
113+
cat $response
114+
115+
# pull out the envelopeId
116+
ENVELOPE_ID=`cat $response | grep envelopeId | sed 's/.*\"envelopeId\": \"//' | sed 's/\",//' | tr -d '\r'`
117+
# Save the envelope id for use by other scripts
118+
echo ${ENVELOPE_ID} > ../ENVELOPE_ID
119+
120+
# cleanup
121+
rm "$request_data"
122+
rm "$response"
123+
rm "$doc1_base64"
124+
rm "$doc2_base64"
125+
rm "$doc3_base64"
126+
127+
echo ""
128+
echo ""
129+
echo "Done."
130+
echo ""
131+

0 commit comments

Comments
 (0)