Skip to content

Commit 6872cdd

Browse files
committed
eg010
1 parent 587b058 commit 6872cdd

File tree

3 files changed

+153
-5
lines changed

3 files changed

+153
-5
lines changed

examples/eg007EnvelopeGetDoc.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ doc_choice=1
2424
output_file_extension=pdf
2525
echo ""
2626
PS3='Select a document or document set to download: '
27-
options=("Documents combined together" "ZIP file" "Document 1" "Document 2" "Document 3")
27+
options=("Document 1" "Document 2" "Document 3" "Certificate of Completion" "Documents combined together" "ZIP file" )
2828
select opt in "${options[@]}"
2929
do
3030
case $opt in
31+
"Certificate of Completion")
32+
doc_choice=certificate
33+
break
34+
;;
3135
"Documents combined together")
3236
doc_choice=combined
3337
break

examples/eg008CreateTemplate.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if [ "${TEMPLATE_ID}" != "" ]; then
3030
echo ${TEMPLATE_ID} > ../TEMPLATE_ID
3131
rm "$response"
3232
echo ""
33-
echo "Done"
33+
echo "Done."
3434
echo ""
3535
exit 0
3636
fi
@@ -60,9 +60,8 @@ printf \
6060
"documents": [
6161
{
6262
"documentBase64": "' > $request_data
63-
cat $doc1_base64 >> $request_data
64-
printf \
65-
'",
63+
cat $doc1_base64 >> $request_data
64+
printf '",
6665
"documentId": "1", "fileExtension": "pdf",
6766
"name": "Lorem Ipsum"
6867
}

examples/eg010SendBinaryDocs.sh

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Send an envelope with three documents using multipart transfer
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+
base_path="https://demo.docusign.net/restapi"
8+
9+
# document 1 (html) has tag **signature_1**
10+
# document 2 (docx) has tag /sn1/
11+
# document 3 (pdf) has tag /sn1/
12+
#
13+
# The envelope has two recipients.
14+
# recipient 1 - signer
15+
# recipient 2 - cc
16+
# The envelope will be sent first to the signer.
17+
# After it is signed, a copy is sent to the cc person.
18+
19+
# temp files
20+
request_data=$(mktemp /tmp/request-eg-010.XXXXXX)
21+
response=$(mktemp /tmp/response-eg-010.XXXXXX)
22+
23+
doc1_path="../demo_documents/doc_1.html"
24+
doc2_path="../demo_documents/World_Wide_Corp_Battle_Plan_Trafalgar.docx"
25+
doc3_path="../demo_documents/World_Wide_Corp_lorem.pdf"
26+
27+
echo ""
28+
echo "Sending the envelope request to DocuSign..."
29+
echo "The envelope has three documents. Processing time will be about 15 seconds."
30+
echo "Results:"
31+
echo ""
32+
33+
# Step 1. Make the JSON part of the final request body
34+
json="
35+
{
36+
"emailSubject": "Please sign this document set",
37+
"documents": [
38+
{
39+
"name": "Order acknowledgement", "fileExtension": "html",
40+
"documentId": "1"
41+
},
42+
{
43+
"name": "Battle Plan", "fileExtension": "docx",
44+
"documentId": "2"
45+
},
46+
{
47+
"name": "Lorem Ipsum", "fileExtension": "pdf",
48+
"documentId": "3"
49+
}
50+
],
51+
"recipients": {
52+
"signers": [
53+
{
54+
"email": "{USER_EMAIL}",
55+
"name": "{USER_FULLNAME}",
56+
"recipientId": "1",
57+
"routingOrder": "1",
58+
"tabs": {
59+
"signHereTabs": [
60+
{
61+
"anchorString": "**signature_1**",
62+
"anchorYOffset": "10",
63+
"anchorUnits": "pixels",
64+
"anchorXOffset": "20"
65+
},
66+
{
67+
"anchorString": "/sn1/",
68+
"anchorYOffset": "10",
69+
"anchorUnits": "pixels",
70+
"anchorXOffset": "20"
71+
}
72+
]
73+
}
74+
}
75+
],
76+
"carbonCopies": [
77+
{
78+
"email": "{USER_EMAIL}",
79+
"name": "Charlie Copy",
80+
"routingOrder": "2",
81+
"recipientId": "2"
82+
}
83+
]
84+
},
85+
"status": "sent"
86+
}
87+
"
88+
89+
# Step 2. Assemble the multipart body
90+
CRLF="\r\n"
91+
boundary="multipartboundary_multipartboundary"
92+
hyphens="--"
93+
94+
printf "${hyphens}" > $request_data
95+
printf "${boundary}" >> $request_data
96+
printf "${CRLF}Content-Type: application/json" >> $request_data
97+
printf "${CRLF}Content-Disposition: form-data" >> $request_data
98+
printf "${CRLF}" >> $request_data
99+
printf "${CRLF}${json}" >> $request_data
100+
101+
# Next add the documents. Each document has its own mime type,
102+
# filename, and documentId. The filename and documentId must match
103+
# the document's info in the JSON.
104+
printf "${CRLF}${hyphens}${boundary}" >> $request_data
105+
printf "${CRLF}Content-Type: text/html" >> $request_data
106+
printf "${CRLF}Content-Disposition: file; filename=\"Order acknowledgement\";documentid=1" >> $request_data
107+
printf "${CRLF}" >> $request_data
108+
printf "${CRLF}" >> $request_data
109+
cat "$doc1_path" >> $request_data
110+
111+
printf "${CRLF}${hyphens}${boundary}" >> $request_data
112+
printf "${CRLF}Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document" >> $request_data
113+
printf "${CRLF}Content-Disposition: file; filename=\"Battle Plan\";documentid=2" >> $request_data
114+
printf "${CRLF}" >> $request_data
115+
printf "${CRLF}" >> $request_data
116+
cat "$doc2_path" >> $request_data
117+
118+
printf "${CRLF}${hyphens}${boundary}" >> $request_data
119+
printf "${CRLF}Content-Type: application/pdf" >> $request_data
120+
printf "${CRLF}Content-Disposition: file; filename=\"Lorem Ipsum\";documentid=3" >> $request_data
121+
printf "${CRLF}" >> $request_data
122+
printf "${CRLF}" >> $request_data
123+
cat "$doc3_path" >> $request_data
124+
125+
# Add closing boundary
126+
printf "${CRLF}${hyphens}${boundary}${hyphens}${CRLF} >> $request_data
127+
128+
curl --header "Authorization: Bearer {ACCESS_TOKEN}" \
129+
--header "Content-Type: multipart/form-data; boundary=${boundary}" \
130+
--data-binary @${request_data} \
131+
--request POST ${base_path}/v2/accounts/{ACCOUNT_ID}/envelopes \
132+
--output $response
133+
134+
echo ""
135+
cat $response
136+
137+
# cleanup
138+
rm "$request_data"
139+
rm "$response"
140+
141+
echo ""
142+
echo ""
143+
echo "Done."
144+
echo ""
145+

0 commit comments

Comments
 (0)