|
| 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