1+ # Send envelope with multiple delivery channels
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+ source ./examples/eSignature/lib/utils.sh
9+
10+ # Choose an additional delivery method.
11+ DELIVERY_METHOD=" 0"
12+ echo " Please choose an additional delivery method:"
13+ echo " Press 1 for SMS."
14+ echo " Press 2 for WhatsApp."
15+ read choice
16+
17+ case $choice in
18+ 1)
19+ DELIVERY_METHOD=" SMS"
20+ ;;
21+ 2)
22+ DELIVERY_METHOD=" WhatsApp"
23+ ;;
24+ * )
25+ echo " Invalid choice. Select 1 or 2."
26+ ;;
27+ esac
28+
29+ # Get a country code and phone number for the signer
30+ GetSignerPhoneNum
31+
32+ # Check for a valid cc email and prompt the user if
33+ # CC_EMAIL and CC_NAME haven't been set in the config file.
34+ CheckForValidCCEmail
35+
36+ # Get a country code and phone number for the CC recipient.
37+ GetCCPhoneNum
38+
39+ # Step 1: Obtain your OAuth token
40+ # Note: Substitute these values with your own
41+ ACCESS_TOKEN=$( cat config/ds_access_token.txt)
42+
43+ # Set up variables for full code example
44+ # Note: Substitute these values with your own
45+ account_id=$( cat config/API_ACCOUNT_ID)
46+
47+ base_path=" https://demo.docusign.net/restapi"
48+
49+ # ***DS.snippet.0.start
50+ # document 1 (html) has tag **signature_1**
51+ # document 2 (docx) has tag /sn1/
52+ # document 3 (pdf) has tag /sn1/
53+ #
54+ # The envelope has two recipients.
55+ # recipient 1 - signer
56+ # recipient 2 - cc
57+ # The envelope will be sent first to the signer.
58+ # After it is signed, a copy is sent to the cc person.
59+
60+ # temp files:
61+ request_data=$( mktemp /tmp/request-eg-002.XXXXXX)
62+ response=$( mktemp /tmp/response-eg-002.XXXXXX)
63+ doc1_base64=$( mktemp /tmp/eg-002-doc1.XXXXXX)
64+ doc2_base64=$( mktemp /tmp/eg-002-doc2.XXXXXX)
65+ doc3_base64=$( mktemp /tmp/eg-002-doc3.XXXXXX)
66+
67+ # Fetch docs and encode
68+ cat demo_documents/doc_1.html | base64 > $doc1_base64
69+ cat demo_documents/World_Wide_Corp_Battle_Plan_Trafalgar.docx | base64 > $doc2_base64
70+ cat demo_documents/World_Wide_Corp_lorem.pdf | base64 > $doc3_base64
71+
72+ echo " "
73+ echo " Sending the envelope request to DocuSign..."
74+ echo " The envelope has three documents. Processing time will be about 15 seconds."
75+ echo " Results:"
76+ echo " "
77+
78+ # Concatenate the different parts of the request
79+ # ds-snippet-start:eSign46Step2
80+ printf \
81+ ' {
82+ "emailSubject": "Please sign this document set",
83+ "documents": [
84+ {
85+ "documentBase64": "' > $request_data
86+ cat $doc1_base64 >> $request_data
87+ printf ' ",
88+ "name": "Order acknowledgement",
89+ "fileExtension": "html",
90+ "documentId": "1"
91+ },
92+ {
93+ "documentBase64": "' >> $request_data
94+ cat $doc2_base64 >> $request_data
95+ printf ' ",
96+ "name": "Battle Plan",
97+ "fileExtension": "docx",
98+ "documentId": "2"
99+ },
100+ {
101+ "documentBase64": "' >> $request_data
102+ cat $doc3_base64 >> $request_data
103+ printf ' ",
104+ "name": "Lorem Ipsum",
105+ "fileExtension": "pdf",
106+ "documentId": "3"
107+ }
108+ ],
109+ "recipients":
110+ {
111+ "carbonCopies":
112+ [
113+ {
114+ "name": "' " ${CC_NAME} " ' ",
115+ "email": "' " ${CC_EMAIL} " ' ",
116+ "recipientId": "2",
117+ "routingOrder": "2",
118+ "deliveryMethod": "Email",
119+ "additionalNotifications": [
120+ {
121+ "phoneNumber":
122+ {
123+ "countryCode": "' " ${CC_PHONE_COUNTRY} " ' ",
124+ "number":"' " ${CC_PHONE_NUMBER} " ' "
125+ },
126+ "secondaryDeliveryMethod": "' " ${DELIVERY_METHOD} " ' "
127+ }
128+ ],
129+ }
130+ ],
131+ "signers":
132+ [
133+ {
134+ "name": "' " ${SIGNER_NAME} " ' ",
135+ "email": "' " ${SIGNER_EMAIL} " ' ",
136+ "recipientId": "1",
137+ "routingOrder": "1",
138+ "deliveryMethod": "Email",
139+ "additionalNotifications": [
140+ {
141+ "phoneNumber":
142+ {
143+ "countryCode": "' " ${SIGNER_PHONE_COUNTRY} " ' ",
144+ "number":"' " ${SIGNER_PHONE_NUMBER} " ' "
145+ },
146+ "secondaryDeliveryMethod": "' " ${DELIVERY_METHOD} " ' "
147+ }
148+ ],
149+ "tabs":
150+ {
151+ "signHereTabs":
152+ [
153+ {
154+ "anchorString": "**signature_1**",
155+ "anchorUnits": "pixels",
156+ "anchorXOffset": "20",
157+ "anchorYOffset": "10"
158+ },
159+ {
160+ "anchorString": "/sn1/",
161+ "anchorUnits": "pixels",
162+ "anchorXOffset": "20",
163+ "anchorYOffset": "10"
164+ }
165+ ]
166+ }
167+ }
168+ ]
169+ },
170+ "status": "sent"
171+ }' >> $request_data
172+ # ds-snippet-end:eSign46Step2
173+
174+ # ds-snippet-start:eSign46Step3
175+ curl --header " Authorization: Bearer ${ACCESS_TOKEN} " \
176+ --header " Content-Type: application/json" \
177+ --data-binary @${request_data} \
178+ --request POST ${base_path} /v2.1/accounts/${account_id} /envelopes \
179+ --output $response
180+ # ds-snippet-end:eSign46Step3
181+
182+ if ` cat $response | grep -q " ACCOUNT_LACKS_PERMISSIONS" ` ; then
183+ echo " This account does not have sufficient permissions to send envelopes via SMS. "
184+ echo " To enable multi-channel delivery, please contact DocuSign Support: "
185+ echo " https://developers.docusign.com/support"
186+ exit 1
187+ fi
188+
189+ echo " "
190+ echo " Response:"
191+ cat $response
192+ echo " "
193+
194+ # pull out the envelopeId
195+ envelope_id=` cat $response | grep envelopeId | sed ' s/.*\"envelopeId\":\"//' | sed ' s/\",.*//' `
196+ # Save the envelope id for use by other scripts
197+ echo " EnvelopeId: ${envelope_id} "
198+ echo ${envelope_id} > config/ENVELOPE_ID
199+
200+ # cleanup
201+ rm " $request_data "
202+ rm " $response "
203+ rm " $doc1_base64 "
204+ rm " $doc2_base64 "
205+ rm " $doc3_base64 "
206+
207+ echo " "
208+ echo " "
209+ echo " Done."
210+ echo " "
0 commit comments