@@ -19,15 +19,20 @@ curl --header "Authorization: Bearer {ACCESS_TOKEN}" \
1919
2020# pull out the templateId if it was returned
2121TEMPLATE_ID=` cat $response | grep templateId | sed ' s/.*\"templateId\": \"//' | sed ' s/\",.*//' `
22+ if [ " ${TEMPLATE_ID} " != " " ]; then
23+ echo " "
24+ echo " Your account already includes the '${template_name} ' template."
25+ # Save the template id for use by other scripts
26+ echo ${TEMPLATE_ID} > ../TEMPLATE_ID
27+ rm " $response "
28+ echo " "
29+ echo " Done"
30+ echo " "
31+ exit 0
32+ fi
2233
23- # Save the template id for use by other scripts
24- echo ${TEMPLATE_ID} > ../TEMPLATE_ID
25-
26-
27- exit 0
34+ # Step 2. Create the template programmatically
2835
29- # document 1 (html) has tag **signature_1**
30- # document 2 (docx) has tag /sn1/
3136# document 3 (pdf) has tag /sn1/
3237#
3338# The envelope has two recipients.
@@ -37,113 +42,156 @@ exit 0
3742# After it is signed, a copy is sent to the cc person.
3843
3944# temp files:
40- request_data=$( mktemp /tmp/request-eg-002.XXXXXX)
41- response=$( mktemp /tmp/response-eg-002.XXXXXX)
42- doc1_base64=$( mktemp /tmp/eg-002-doc1.XXXXXX)
43- doc2_base64=$( mktemp /tmp/eg-002-doc2.XXXXXX)
44- doc3_base64=$( mktemp /tmp/eg-002-doc3.XXXXXX)
45-
46- # Fetch docs and encode
47- cat ../demo_documents/doc_1.html | base64 > $doc1_base64
48- cat ../demo_documents/World_Wide_Corp_Battle_Plan_Trafalgar.docx | base64 > $doc2_base64
49- cat ../demo_documents/World_Wide_Corp_lorem.pdf | base64 > $doc3_base64
45+ request_data=$( mktemp /tmp/request-eg-008.XXXXXX)
46+ doc1_base64=$( mktemp /tmp/eg-008-doc1.XXXXXX)
5047
5148echo " "
52- echo " Sending the envelope request to DocuSign..."
53- echo " The envelope has three documents. Processing time will be about 15 seconds."
54- echo " Results:"
49+ echo " Sending the template create request to DocuSign..."
5550echo " "
5651
52+ # Fetch docs and encode
53+ cat ../demo_documents/World_Wide_Corp_fields.pdf | base64 > $doc1_base64
54+
55+
5756# Concatenate the different parts of the request
5857printf \
5958' {
60- "emailSubject": "Please sign this document set",
6159 "documents": [
6260 {
6361 "documentBase64": "' > $request_data
6462cat $doc1_base64 >> $request_data
6563printf \
6664' ",
67- "name": "Order acknowledgement",
68- "fileExtension": "html",
69- "documentId": "1"
70- },
71- {
72- "documentBase64": "' >> $request_data
73- cat $doc2_base64 >> $request_data
74- printf \
75- ' ",
76- "name": "Battle Plan",
77- "fileExtension": "docx",
78- "documentId": "2"
79- },
80- {
81- "documentBase64": "' >> $request_data
82- cat $doc3_base64 >> $request_data
83- printf \
84- ' ",
85- "name": "Lorem Ipsum",
86- "fileExtension": "pdf",
87- "documentId": "3"
65+ "documentId": "1", "fileExtension": "pdf",
66+ "name": "Lorem Ipsum"
8867 }
8968 ],
69+ "emailSubject": "Please sign this document",
70+ "envelopeTemplateDefinition": {
71+ "description": "Example template created via the API",
72+ "name": "Example Signer and CC template",
73+ "shared": "false"
74+ },
9075 "recipients": {
9176 "carbonCopies": [
92- {
93- "email": "{USER_EMAIL}",
94- "name": "Charles Copy",
95- "recipientId": "2",
96- "routingOrder": "2"
97- }
77+ {"recipientId": "2", "roleName": "cc", "routingOrder": "2"}
9878 ],
9979 "signers": [
10080 {
101- "email": "{USER_EMAIL}",
102- "name": "{USER_FULLNAME}",
103- "recipientId": "1",
104- "routingOrder": "1",
81+ "recipientId": "1", "roleName": "signer", "routingOrder": "1",
10582 "tabs": {
83+ "checkboxTabs": [
84+ {
85+ "documentId": "1", "pageNumber": "1",
86+ "tabLabel": "ckAuthorization", "xPosition": "75",
87+ "yPosition": "417"
88+ },
89+ {
90+ "documentId": "1", "pageNumber": "1",
91+ "tabLabel": "ckAuthentication", "xPosition": "75",
92+ "yPosition": "447"
93+ },
94+ {
95+ "documentId": "1", "pageNumber": "1",
96+ "tabLabel": "ckAgreement", "xPosition": "75",
97+ "yPosition": "478"
98+ },
99+ {
100+ "documentId": "1", "pageNumber": "1",
101+ "tabLabel": "ckAcknowledgement", "xPosition": "75",
102+ "yPosition": "508"
103+ }
104+ ],
105+ "listTabs": [
106+ {
107+ "documentId": "1", "font": "helvetica",
108+ "fontSize": "size14",
109+ "listItems": [
110+ {"text": "Red", "value": "red"},
111+ {"text": "Orange", "value": "orange"},
112+ {"text": "Yellow", "value": "yellow"},
113+ {"text": "Green", "value": "green"},
114+ {"text": "Blue", "value": "blue"},
115+ {"text": "Indigo", "value": "indigo"},
116+ {"text": "Violet", "value": "violet"}
117+ ],
118+ "pageNumber": "1", "required": "false",
119+ "tabLabel": "list", "xPosition": "142",
120+ "yPosition": "291"
121+ }
122+ ],
123+ "radioGroupTabs": [
124+ {
125+ "documentId": "1", "groupName": "radio1",
126+ "radios": [
127+ {
128+ "pageNumber": "1", "required": "false",
129+ "value": "white", "xPosition": "142",
130+ "yPosition": "384"
131+ },
132+ {
133+ "pageNumber": "1", "required": "false",
134+ "value": "red", "xPosition": "74",
135+ "yPosition": "384"
136+ },
137+ {
138+ "pageNumber": "1", "required": "false",
139+ "value": "blue", "xPosition": "220",
140+ "yPosition": "384"
141+ }
142+ ]
143+ }
144+ ],
106145 "signHereTabs": [
107146 {
108- "anchorString": "**signature_1**",
109- "anchorUnits": "pixels",
110- "anchorXOffset": "20",
111- "anchorYOffset": "10"
147+ "documentId": "1", "pageNumber": "1",
148+ "xPosition": "191", "yPosition": "148"
149+ }
150+ ],
151+ "textTabs": [
152+ {
153+ "documentId": "1", "font": "helvetica",
154+ "fontSize": "size14", "height": 23,
155+ "pageNumber": "1", "required": "false",
156+ "tabLabel": "text", "width": 84,
157+ "xPosition": "153", "yPosition": "230"
112158 },
113159 {
114- "anchorString": "/sn1/",
115- "anchorUnits": "pixels",
116- "anchorXOffset": "20",
117- "anchorYOffset": "10"
160+ "documentId": "1", "font": "helvetica",
161+ "fontSize": "size14", "height": 23,
162+ "pageNumber": "1", "required": "false",
163+ "tabLabel": "numbersOnly", "width": 84,
164+ "xPosition": "153", "yPosition": "260"
118165 }
119166 ]
120167 }
121168 }
122169 ]
123170 },
124- "status": "sent "
171+ "status": "created "
125172}' >> $request_data
126173
127174curl --header " Authorization: Bearer {ACCESS_TOKEN}" \
128175 --header " Content-Type: application/json" \
129176 --data-binary @${request_data} \
130- --request POST https://demo.docusign.net/restapi/v2/accounts/{ACCOUNT_ID}/envelopes \
177+ --request POST https://demo.docusign.net/restapi/v2/accounts/{ACCOUNT_ID}/templates \
131178 --output $response
132179
133180echo " "
181+ echo " Results:"
134182cat $response
135183
136184# pull out the envelopeId
137- ENVELOPE_ID=` cat $response | grep envelopeId | sed ' s/.*\"envelopeId\": \"//' | sed ' s/\",//' | tr -d ' \r' `
138- # Save the envelope id for use by other scripts
139- echo ${ENVELOPE_ID} > ../ENVELOPE_ID
185+ TEMPLATE_ID=` cat $response | grep templateId | sed ' s/.*\"templateId\": \"//' | sed ' s/\",.*//' `
186+ echo " "
187+ echo " Template '${template_name} ' was created! Template ID ${TEMPLATE_ID} ."
188+ # Save the template id for use by other scripts
189+ echo ${TEMPLATE_ID} > ../TEMPLATE_ID
140190
141191# cleanup
142192rm " $request_data "
143193rm " $response "
144194rm " $doc1_base64 "
145- rm " $doc2_base64 "
146- rm " $doc3_base64 "
147195
148196echo " "
149197echo " "
0 commit comments