|
| 1 | +# Embedded signing ceremony |
| 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 ../Env.txt |
| 9 | + |
| 10 | +# |
| 11 | +# Step 1. Create the envelope. |
| 12 | +# The signer recipient includes a clientUserId setting |
| 13 | +# Step 2. Create a recipient view (a signing ceremony view) |
| 14 | +# that the signer will directly open in their browser to sign. |
| 15 | + |
| 16 | +# Step 1... |
| 17 | +# |
| 18 | +# document 1 (pdf) has tag /sn1/ |
| 19 | +# The envelope has two recipients. |
| 20 | +# recipient 1 - signer |
| 21 | +# recipient 2 - cc |
| 22 | +# The envelope will be sent first to the signer. |
| 23 | +# After it is signed, a copy is sent to the cc person. |
| 24 | + |
| 25 | +# temp files: |
| 26 | +request_data=$(mktemp /tmp/request-eg-001.XXXXXX) |
| 27 | +response=$(mktemp /tmp/response-eg-001.XXXXXX) |
| 28 | +doc1_base64=$(mktemp /tmp/eg-001-doc1.XXXXXX) |
| 29 | + |
| 30 | +echo "" |
| 31 | +echo "Sending the envelope request to DocuSign..." |
| 32 | + |
| 33 | +# Fetch doc and encode |
| 34 | +cat ../demo_documents/World_Wide_Corp_lorem.pdf | base64 > $doc1_base64 |
| 35 | +# Concatenate the different parts of the request |
| 36 | +printf \ |
| 37 | +'{ |
| 38 | + "emailSubject": "Please sign this document set", |
| 39 | + "documents": [ |
| 40 | + { |
| 41 | + "documentBase64": "' > $request_data |
| 42 | +cat $doc1_base64 >> $request_data |
| 43 | +printf \ |
| 44 | +'", |
| 45 | + "name": "Lorem Ipsum", |
| 46 | + "fileExtension": "pdf", |
| 47 | + "documentId": "1" |
| 48 | + } |
| 49 | + ], |
| 50 | + "recipients": { |
| 51 | + "carbonCopies": [ |
| 52 | + { |
| 53 | + "email": "{USER_EMAIL}", |
| 54 | + "name": "Charles Copy", |
| 55 | + "recipientId": "2", |
| 56 | + "routingOrder": "2" |
| 57 | + } |
| 58 | + ], |
| 59 | + "signers": [ |
| 60 | + { |
| 61 | + "email": "{USER_EMAIL}", |
| 62 | + "name": "{USER_FULLNAME}", |
| 63 | + "recipientId": "1", |
| 64 | + "routingOrder": "1", |
| 65 | + "clientUserId": "1000", |
| 66 | + "tabs": { |
| 67 | + "signHereTabs": [ |
| 68 | + { |
| 69 | + "anchorString": "/sn1/", |
| 70 | + "anchorUnits": "pixels", |
| 71 | + "anchorXOffset": "20", |
| 72 | + "anchorYOffset": "10" |
| 73 | + } |
| 74 | + ] |
| 75 | + } |
| 76 | + } |
| 77 | + ] |
| 78 | + }, |
| 79 | + "status": "sent" |
| 80 | +}' >> $request_data |
| 81 | + |
| 82 | +curl --header "Authorization: Bearer {ACCESS_TOKEN}" \ |
| 83 | + --header "Content-Type: application/json" \ |
| 84 | + --data-binary @${request_data} \ |
| 85 | + --request POST https://demo.docusign.net/restapi/v2/accounts/{ACCOUNT_ID}/envelopes |
| 86 | + --output ${response} |
| 87 | + |
| 88 | +echo "" |
| 89 | +echo "Response:" |
| 90 | +cat $response |
| 91 | + |
| 92 | +# pull out the envelopeId |
| 93 | +ENVELOPE_ID=`sed 's/{\"access_token\":\"//' $response | |
| 94 | +sed 's/\",\"token_type\":\"Bearer\"\,\"refresh_token\":\".*\",\"expires_in\":.*}//'` |
| 95 | + |
| 96 | + |
| 97 | +#echo "" |
| 98 | +#echo "" |
| 99 | +#echo "Files" |
| 100 | +#echo "$request_data" |
| 101 | +#echo "$doc1_base64" |
| 102 | +#echo "$doc2_base64" |
| 103 | +#echo "$doc3_base64" |
| 104 | + |
| 105 | +# cleanup |
| 106 | +rm "$request_data" |
| 107 | +rm "$doc1_base64" |
| 108 | +rm "$doc2_base64" |
| 109 | +rm "$doc3_base64" |
| 110 | + |
| 111 | +echo "" |
| 112 | +echo "" |
| 113 | +echo "Done." |
| 114 | +echo "" |
| 115 | + |
| 116 | + |
0 commit comments