diff --git a/README.md b/README.md index 058bdbc..a3e35e5 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,30 @@ This repo includes bash scripts that use curl to demonstrate: 1. **Send an envelope with a remote (email) signer using Identity Verification.** [Source.](./examples/eg023SigningViaEmailWithIDVAuthentication.sh) This example sends an envelope using remote (email) signing requiring the recipient to validate their identity via a government issued ID. +1. **Create a permissions profile to set against a user group.** + [Source.](./examples/eg024CreatingPermissionProfiles.sh) + This example creates a permissions profile that can be used to set account permissions for the different user groups associated with your account. +1. **Set a permissions profile against a user group.** + [Source.](./examples/eg025SettingPermissionProfiles.sh) + This example updates a user group by setting the permissions profile. +1. **Update individual settings on a permissions profile.** + [Source.](./examples/eg026UpdatingIndividualPermission.sh) + This example updates a user group by setting the permissions profile. +1. **Delete a permissions profile** + [Source.](./examples/eg027DeletingPermissions.sh) + This example deletes a permissions profile. +1. **Creating a brand** + [Source.](./examples/eg028CreatingABrand.sh) + This example creates a brand on your account that can be used to override style elements on envelopes. +1. **Apply a brand to an envelope** + [Source.](./examples/eg029ApplyingBrandEnvelope.sh) + This example sends a branded envelope. +1. **Apply a brand to a template** + [Source.](./examples/eg030ApplyingBrandTemplate.sh) + This example sends a branded templated envelope. +1. **Sending bulk envelopes to multiple recipients** + [Source.](./examples/eg031BulkSending.sh) + This example creates and sends a bulk envelope by generating a bulk recipient list and initiating a bulk send. ## Installation @@ -148,6 +172,15 @@ bash eg020SigningViaEmailWithSmsAuthentication.sh bash eg021SigningViaEmailWithPhoneAuthentication.sh bash eg022SigningViaEmailWithKnoweldgeBasedAuthentication.sh bash eg023SigningViaEmailWithIDVAuthentication.sh +bash eg024CreatingPermissionProfiles.sh +bash eg025SettingPermissionProfiles.sh +bash eg026UpdatingIndividualPermission.sh +bash eg027DeletingPermissions.sh +bash eg028CreatingABrand.sh +bash eg029ApplyingBrandEnvelope.sh +bash eg030ApplyingBrandTemplate.sh +bash eg031BulkSending.sh + # Note: to use example 14 you must also configure a # payment gateway for your account. diff --git a/examples/eg024CreatingPermissionProfiles.sh b/examples/eg024CreatingPermissionProfiles.sh new file mode 100644 index 0000000..7688a11 --- /dev/null +++ b/examples/eg024CreatingPermissionProfiles.sh @@ -0,0 +1,81 @@ +# Create Permission Profile + +# Step 1: Obtain your OAuth token +# Note: Substitute these values with your own +# Set up variables for full code example +ACCESS_TOKEN="{ACCESS_TOKEN}" +API_ACCOUNT_ID="{ACCOUNT_ID}" + +# Check that we're in a bash shell +if [[ $SHELL != *"bash"* ]]; then + echo "PROBLEM: Run these scripts from within the bash shell." +fi +BASE_PATH="https://demo.docusign.net/restapi" + +# Step 2: Construct your API headers +declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ + '--header' "Accept: application/json" \ + '--header' "Content-Type: application/json") + +# Step 3: Construct the request body for your pemisison profile +# Create a temporary file to store the request body +request_data=$(mktemp /tmp/request-perm-001.XXXXXX) +printf \ +'{ + "permissionProfileName": "Ipsum Reader", + "settings" : { + "useNewDocuSignExperienceInterface":0, + "allowBulkSending":"true", + "allowEnvelopeSending":"true", + "allowSignerAttachments":"true", + "allowTaggingInSendAndCorrect":"true", + "allowWetSigningOverride":"true", + "allowedAddressBookAccess":"personalAndShared", + "allowedTemplateAccess":"share", + "enableRecipientViewingNotifications":"true", + "enableSequentialSigningInterface":"true", + "receiveCompletedSelfSignedDocumentsAsEmailLinks":"false", + "signingUiVersion":"v2", + "useNewSendingInterface":"true", + "allowApiAccess":"true", + "allowApiAccessToAccount":"true", + "allowApiSendingOnBehalfOfOthers":"true", + "allowApiSequentialSigning":"true", + "enableApiRequestLogging":"true", + "allowDocuSignDesktopClient":"false", + "allowSendersToSetRecipientEmailLanguage":"true", + "allowVaulting":"false", + "allowedToBeEnvelopeTransferRecipient":"true", + "enableTransactionPointIntegration":"false", + "powerFormRole":"admin", + "vaultingMode":"none" + } +}' >> $request_data + +# Step 4: a) Call the eSignature API +# b) Display the JSON response +# Create a temporary file to store the response +response=$(mktemp /tmp/response-perm.XXXXXX) + +Status=$(curl -w '%{http_code}' -i --request POST ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/permission_profiles \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) + +# If the Status code returned is greater than 201 (OK/Accepted), display an error message along with the API response +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Unable to create a new permissions profile." + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +cat $response +echo "" + +# Remove the temporary files +rm "$request_data" +rm "$response" diff --git a/examples/eg025SettingPermissionProfiles.sh b/examples/eg025SettingPermissionProfiles.sh new file mode 100644 index 0000000..e9963fd --- /dev/null +++ b/examples/eg025SettingPermissionProfiles.sh @@ -0,0 +1,62 @@ +# Setting a permission profile + +# Step 1: Obtain your OAuth token +# Set up variables for full code example +# Note: Substitute these values with your own +ACCESS_TOKEN="{ACCESS_TOKEN}" +API_ACCOUNT_ID="{API_ACCOUNT_ID}" +PROFILE_ID="{PROFILE_ID}" +GROUP_ID="{GROUP_ID}" + + +# Check that we're in a bash shell +if [[ $SHELL != *"bash"* ]]; then + echo "PROBLEM: Run these scripts from within the bash shell." +fi +BASE_PATH="https://demo.docusign.net/restapi" + +# Step 2: Construct your API headers +declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ + '--header' "Accept: application/json" \ + '--header' "Content-Type: application/json") + +# Step 3: Construct your request body +# Create a temporary file to store the request body +request_data=$(mktemp /tmp/request-perm-001.XXXXXX) +printf \ +"{ + \"groups\": [ + { + \"groupId\": "${GROUP_ID}", + \"permissionProfileId\": "${PROFILE_ID}" + } + ] +}}" >> $request_data + +# Step 4: a) Call the eSignature API +# b) Display the JSON response +# Create a temporary file to store the response +response=$(mktemp /tmp/response-perm.XXXXXX) + +Status=$(curl -w '%{http_code}' -i --request PUT ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/groups \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) + +# If the Status code returned is greater than 201 (OK/Accepted), display an error message along with the API response +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Unable to set group permissions profile." + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +cat $response +echo "" + +# Remove the temporary files +rm "$request_data" +rm "$response" diff --git a/examples/eg026UpdatingIndividualPermission.sh b/examples/eg026UpdatingIndividualPermission.sh new file mode 100644 index 0000000..1e5845c --- /dev/null +++ b/examples/eg026UpdatingIndividualPermission.sh @@ -0,0 +1,82 @@ +# Updating Individual Permissions + +# Step 1: Obtain your OAuth token +# Note: Substitute these values with your own +# Set up variables for full code example +ACCESS_TOKEN="{ACCESS_TOKEN}" +API_ACCOUNT_ID="{API_ACCOUNT_ID}" +PERMISSION_PROFILE_ID="{PERMISSION_PROFILE_ID}" + +# Check that we're in a bash shell +if [[ $SHELL != *"bash"* ]]; then + echo "PROBLEM: Run these scripts from within the bash shell." +fi +base_path="https://demo.docusign.net/restapi" + +# Step 2: Construct your API headers +declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ + '--header' "Accept: application/json" \ + '--header' "Content-Type: application/json") + +# Step 3: Construct the request body for your pemisison profile +# Create a temporary file to store the request body +request_data=$(mktemp /tmp/request-perm-001.XXXXXX) +printf \ +'{ + "permissionProfileName": "Ipsum Reader", + "settings" : { + "useNewDocuSignExperienceInterface":0, + "allowBulkSending":"true", + "allowEnvelopeSending":"true", + "allowSignerAttachments":"true", + "allowTaggingInSendAndCorrect":"true", + "allowWetSigningOverride":"true", + "allowedAddressBookAccess":"personalAndShared", + "allowedTemplateAccess":"share", + "enableRecipientViewingNotifications":"true", + "enableSequentialSigningInterface":"true", + "receiveCompletedSelfSignedDocumentsAsEmailLinks":"false", + "signingUiVersion":"v2", + "useNewSendingInterface":"true", + "allowApiAccess":"true", + "allowApiAccessToAccount":"true", + "allowApiSendingOnBehalfOfOthers":"true", + "allowApiSequentialSigning":"true", + "enableApiRequestLogging":"true", + "allowDocuSignDesktopClient":"false", + "allowSendersToSetRecipientEmailLanguage":"true", + "allowVaulting":"false", + "allowedToBeEnvelopeTransferRecipient":"true", + "enableTransactionPointIntegration":"false", + "powerFormRole":"admin", + "vaultingMode":"none" + } +}' >> $request_data + +# Step 4: a) Call the eSignature API +# b) Display the JSON response +# Create a temporary file to store the response +response=$(mktemp /tmp/response-perm.XXXXXX) + +Status=$(curl -w '%{http_code}' -i --request POST ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/permission_profiles/${PERMISSION_PROFILE_ID} \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) + +# If the Status code returned is greater than 201 (OK/Accepted), display an error message along with the API response +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Updating Individual Permission Settings failed." + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +cat $response +echo "" + +# Remove the temporary files +rm "$request_data" +rm "$response" diff --git a/examples/eg027DeletingPermissions.sh b/examples/eg027DeletingPermissions.sh new file mode 100644 index 0000000..059a64a --- /dev/null +++ b/examples/eg027DeletingPermissions.sh @@ -0,0 +1,46 @@ +# Delete a permission profile + +# Step 1: Obtain your OAuth token +# Note: Substitute these values with your own +# Set up variables for full code example +ACCESS_TOKEN="{ACCESS_TOKEN}" +API_ACCOUNT_ID="{ACCOUNT_ID}" +PROFILE_ID="{PROFILE_ID]" + +# Check that we're in a bash shell +if [[ $SHELL != *"bash"* ]]; then + echo "PROBLEM: Run these scripts from within the bash shell." +fi +BASE_PATH="https://demo.docusign.net/restapi" + +#Step 2: Construct your API headers +declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ + '--header' "Accept: application/json" \ + '--header' "Content-Type: application/json") + +# Step 3: a) Call the eSignature API +# b) Display the JSON response +# Create a temporary file to store the response +response=$(mktemp /tmp/response-perm.XXXXXX) + +Status=$(curl -w '%{http_code}' -i --request DELETE ${BASE_PATH}/v2.1/accounts/${APIAccountID}/permission_profiles/${PROFILE_ID} \ + "${Headers[@]}" \ + --output ${response}) + +# If the Status code returned is greater than 201 (OK/Accepted), display an error message along with the API response +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Unable to delete the permission profile." + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +cat $response +echo "" + +# Remove the temporary files +rm "$request_data" +rm "$response" diff --git a/examples/eg028CreatingABrand.sh b/examples/eg028CreatingABrand.sh new file mode 100644 index 0000000..b320cd5 --- /dev/null +++ b/examples/eg028CreatingABrand.sh @@ -0,0 +1,57 @@ +# Creating a brand + +# Step 1: Obtain your OAuth token +# Note: Substitute these values with your own +# Set up variables for full code example +ACCESS_TOKEN="{ACCESS_TOKEN}" +API_ACCOUNT_ID="{API_ACCOUNT_ID}" + +# Check that we're in a bash shell +if [[ $SHELL != *"bash"* ]]; then + echo "PROBLEM: Run these scripts from within the bash shell." +fi +BASE_PATH="https://demo.docusign.net/restapi" + +# Step 2: Construct your API headers +declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ + '--header' "Accept: application/json" \ + '--header' "Content-Type: application/json") + +# Step 3: Construct the request body +# Create a temporary file to store the request body +request_data=$(mktemp /tmp/request-brand-001.XXXXXX) +printf \ +'{ + + "brandName": "Sample Corp.", + "defaultBrandLanguage": "en" + +}' >> $request_data + +# Step 4: a) Call the eSignature API +# b) Display the JSON response +# Create a temporary file to store the response +response=$(mktemp /tmp/response-brand.XXXXXX) + +Status=$(curl -w '%{http_code}' -i --request POST ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/brands \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) + +# If the Status code returned is greater than 201 (OK/Accepted), display an error message along with the API response +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Creating a new brand has failed." + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +cat $response +echo "" + +# Remove the temporary files +rm "$request_data" +rm "$response" diff --git a/examples/eg029ApplyingBrandEnvelope.sh b/examples/eg029ApplyingBrandEnvelope.sh new file mode 100644 index 0000000..c83ca97 --- /dev/null +++ b/examples/eg029ApplyingBrandEnvelope.sh @@ -0,0 +1,84 @@ +# Applying a Brand to an envelope + +# Step 1: Obtain your OAuth token +# Note: Substitute these values with your own +# Set up variables for full code example +ACCESS_TOKEN="{ACCESS_TOKEN}" +API_Account_ID="{API_ACCOUNT_ID}" +Brand_ID="{BRAND_ID}" + +# Check that we're in a bash shell +if [[ $SHELL != *"bash"* ]]; then + echo "PROBLEM: Run these scripts from within the bash shell." +fi +base_path="https://demo.docusign.net/restapi" + +#Step 2: Construct your API headers +declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ + '--header' "Accept: application/json" \ + '--header' "Content-Type: application/json") + +# Step 3: Construct the request body +# Create a temporary file to store the request body +request_data=$(mktemp /tmp/request-brand-001.XXXXXX) +printf \ +'{ + "documents": [{ + "documentBase64": "DQoNCg0KCQkJCXRleHQgZG9jDQoNCg0KDQoNCg0KUk0gIwlSTSAjCVJNICMNCg0KDQoNClxzMVwNCg0KLy9hbmNoMSANCgkvL2FuY2gyDQoJCS8vYW5jaDM=", + "documentId": "1", + "fileExtension": "txt", + "name": "NDA" + }], + "emailBlurb": "Sample text for email body", + "emailSubject": "Please Sign", + "envelopeIdStamping": "true", + "recipients": { + "signers": [{ + "name": "Alice UserName", + "email": "alice.username@example.com", + "roleName": "signer", + "note": "", + "routingOrder": 1, + "status": "sent", + "tabs": { + "signHereTabs": [{ + "documentId": "1", + "name": "SignHereTab", + "pageNumber": "1", + "recipientId": "1", + "tabLabel": "SignHereTab", + "xPosition": "75", + "yPosition": "572" + }] + }, + "deliveryMethod": "email", + "recipientId": "1", + "brandId": "'"$BRAND_ID"'" + }] + }, + "status": "Sent" +}' >> $request_data + +# Step 4: a) Call the eSignature API +# b) Display the JSON response +# Create a temporary file to store the response +response=$(mktemp /tmp/response-brand.XXXXXX) +Status=$(curl -w '%{http_code}' -i --request POST ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/envelopes \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) +# If the Status code returned is greater than 201 (OK/Accepted), display an error message along with the API response +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Creating a new envelope has failed." + echo "" + cat $response + exit 1 +fi +echo "" +echo "Response:" +cat $response +echo "" +# Remove the temporary files +rm "$request_data" +rm "$response" \ No newline at end of file diff --git a/examples/eg030ApplyingBrandTemplate.sh b/examples/eg030ApplyingBrandTemplate.sh new file mode 100644 index 0000000..53ecb04 --- /dev/null +++ b/examples/eg030ApplyingBrandTemplate.sh @@ -0,0 +1,60 @@ +# Applying a Brand to a template + +# Step 1: Obtain your OAuth token +# Note: Substitute these values with your own +# Set up variables for full code example +ACCESS_TOKEN="{ACCESS_TOKEN}" +API_ACCOUNT_ID="{API_ACCOUNT_ID}" +BRAND_ID="{BRAND_ID}" +TEMPLATE_ID="{TEMPLATE_ID}" + +#Step 2: Construct your API headers +declare -a Headers=('--header' "Authorization: Bearer {ACCESS_TOKEN}" \ + '--header' "Accept: application/json" \ + '--header' "Content-Type: application/json") + +# Step 3: Construct the request body +# Create a temporary file to store the request body +request_data=$(mktemp /tmp/request-brand-001.XXXXXX) +printf \ +'{ + "templateId": "'$TEMPLATE_ID'", + "brandId": "'$BRAND_ID'", + "templateRoles": [ + { + "email": "alice.username@example.com", + "name": "Alice UserName", + "roleName": "signer" + }, + { + "email": "charlie.copy@example.com", + "name": "Charlie Copy", + "roleName": "cc" + } + ], + "status": "sent" +}' >> $request_data + +# Step 4: a) Call the eSignature API +# b) Display the JSON response +# Create a temporary file to store the response +response=$(mktemp /tmp/response-brand.XXXXXX) +Status=$(curl -w '%{http_code}' -i --request POST ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/envelopes \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) +# If the Status code returned is greater than 201 (OK/Accepted), display an error message along with the API response +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Creating a new envelope has failed." + echo "" + cat $response + exit 1 +fi +echo "" +echo "Response:" +cat $response +echo "" +# Remove the temporary files +rm "$request_data" +rm "$response" \ No newline at end of file diff --git a/examples/eg031BulkSending.sh b/examples/eg031BulkSending.sh new file mode 100644 index 0000000..45d007c --- /dev/null +++ b/examples/eg031BulkSending.sh @@ -0,0 +1,320 @@ +# Bulk sending envelopes to multiple recipients + +# Step 1: Create your API Headers +# Note: These values are not valid, but are shown for example purposes only! +ACCESS_TOKEN="{ACCESS_TOKEN}" +API_ACCOUNT_ID="{API_ACCOUNT_ID}" + + +BASE_PATH="https://demo.docusign.net/restapi" + + +# Step 2: Construct your API headers +declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ + '--header' "Accept: application/json, text/plain, */*" \ + '--header' "Content-Type: application/json;charset=UTF-8" \ + '--header' "Accept-Encoding: gzip, deflate, br" \ + '--header' "Accept-Language: en-US,en;q=0.9") + +# Step 3: Submit the Bulk List +# Create a temporary file to store the JSON body +# The JSON body must contain the recipient role, recipientId, name, and email. +request_data=$(mktemp /tmp/request-bs.XXXXXX) +printf \ +'{ + "name": "sample.csv", + "bulkCopies": [{ + "recipients": [{ + "recipientId": "39542944", + "role": "signer", + "tabs": [], + "name": "Alice UserName", + "email": "alice.username@example.com" + }, + { + "recipientId": "84754526", + "role": "cc", + "tabs": [], + "name": "Bob CarbonCopied", + "email": "bob.carboncopy@example.com" + }], + "customFields": [] + }, + { + "recipients": [{ + "recipientId": "39542944", + "role": "signer", + "tabs": [], + "name": "Carol NextUser", + "email": "carol.nextuser@example.com" + }, + { + "recipientId": "84754526", + "role": "cc", + "tabs": [], + "name": "Dave NextCarbon", + "email": "dave.nextcarbon@example.com" + }], + "customFields": [] + }] +} +' >> $request_data + +# Make a POST call to the bulk_send_lists endpoint, this will be referenced in future API calls. +# Display the JSON structure of the API response +# Create a temporary file to store the response +echo "" +echo "Posting Bulk Send List" +echo "" +response=$(mktemp /tmp/response-bs.XXXXXX) +Status=$(curl -w '%{http_code}' -i --request POST ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/bulk_send_lists \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) + +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Posting of the Bulk List has failed" + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +cat $response +echo "" + +#Obtain the BULK_LIST_ID from the JSON response +BULK_LIST_ID=`cat $response | grep listId | sed 's/.*\"listId\":\"//' | sed 's/\",.*//'` + +# Remove the temporary files +rm "$request_data" +rm "$response" + + +# Step 4 : Create your draft envelope +# Create a temporary file to store the JSON body + +base64="DQoNCg0KCQkJCXRleHQgZG9jDQoNCg0KDQoNCg0KUk0gIwlSTSAjCVJNICMNCg0KDQoNClxzMVwNCg0KLy9hbmNoMSANCgkvL2FuY2gyDQoJCS8vYW5jaDM=" +request_data=$(mktemp /tmp/request-bs.XXXXXX) +printf \ +'{ + "documents": [{ + "documentBase64": "'"$base64"'", + "documentId": "1", + "fileExtension": "txt", + "name": "NDA" + }], + "envelopeIdStamping": "true", + "emailSubject": "Please sign", + "recipients": { + }, + + "status": "created" +} +' >> $request_data + +echo "" +echo "Creating a draft envelope." +echo "" +response=$(mktemp /tmp/response-bs.XXXXXX) +Status=$(curl -w '%{http_code}' -i --request POST ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/envelopes \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) + +#If the Status code returned is greater than 201 (OK / Accepted), display an error message along with the API response. +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Creation of the draft envelope has failed" + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +cat $response +echo "" + +#Obtain the envelopeId from the API response. +ENVELOPE_ID=`cat $response | grep envelopeId | sed 's/.*\"envelopeId\":\"//' | sed 's/\",.*//'` + +#Remove the temporary files +rm "$response" +rm "$request_data" + +# Step 5: Add an envelope custom field set to the value of your listId +# This Custom Field is used for tracking your Bulk Send via the Envelopes::Get method +# Create a temporary file to store the JSON body +request_data=$(mktemp /tmp/request-bs.XXXXXX) +printf \ +'{ + "listCustomFields": [], + "textCustomFields": [{ + "name": "mailingListId", + "required": false, + "show": false, + "value": "'$BULK_LIST_ID'" + }] +} +' >> $request_data +echo "" +echo "Adding the listId as an envelope custom field." +echo "" +response=$(mktemp /tmp/response-bs.XXXXXX) +Status=$(curl -w '%{http_code}' -i --request POST ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/envelopes/${ENVELOPE_ID}/custom_fields \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) + +#If the Status code returned is greater than 201 (OK / Accepted), display an error message along with the API response. +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Addition of the listId to the envelope has failed" + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +cat $response +echo "" + +#Remove the temporary file + +rm "$response" +rm "$request_data" + +# Step 6: Add placeholder recipients. These will be replaced by the details provided in the Bulk List uploaded during Step 2 +# Note: The name / email format used is: +# Name: Multi Bulk Recipients::{rolename} +# Email: MultiBulkRecipients-{rolename}@docusign.com + +# Create a temporary file to store the JSON body +request_data=$(mktemp /tmp/request-bs.XXXXXX) +printf \ +'{ + "signers": [{ + "name": "Multi Bulk Recipient::signer", + "email": "multiBulkRecipients-signer@docusign.com", + "roleName": "signer", + "note": "", + "routingOrder": 1, + "status": "created", + "templateAccessCodeRequired": null, + "deliveryMethod": "email", + "recipientId": "1", + "recipientType": "signer" + }, + { + "name": "Multi Bulk Recipient::cc", + "email": "multiBulkRecipients-cc@docusign.com", + "roleName": "cc", + "note": "", + "routingOrder": 1, + "status": "created", + "templateAccessCodeRequired": null, + "deliveryMethod": "email", + "recipientId": "2", + "recipientType": "signer" + }] +} +' >> $request_data + +echo "" +echo "Adding placeholder recipients to the envelope." +echo "" +response=$(mktemp /tmp/response-bs.XXXXXX) +Status=$(curl -w '%{http_code}' -i --request POST ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/envelopes/${ENVELOPE_ID}/recipients \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) + +#If the Status code returned is greater than 201 (OK / Accepted), display an error message along with the API response. +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Addition of the placeholder recipients has failed" + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +cat $response +echo "" + +#Remove the temporary file + +rm "$response" +rm "$request_data" + +# Step 7: Initiate the Bulk Send by posting your listId obtained from Step 2, and the envelopeId obtained in step 4. +# Target endpoint: {ACCOUNT_ID}/bulk_send_lists/{LIST_ID}/send +printf \ +'{ + "listId": "'"${BULK_LIST_ID}"'"", + "envelopeOrTemplateId": "'"${ENVELOPE_ID}"'", +} +' >> $request_data + +echo "" +echo "Initiating the Bulk Send." +echo "" +response=$(mktemp /tmp/response-bs.XXXXXX) +Status=$(curl -w '%{http_code}' -i --request POST ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/bulk_send_lists/${BULK_LIST_ID}/send \ + "${Headers[@]}" \ + --data-binary @${request_data} \ + --output ${response}) + +#If the Status code returned is greater than 201 (OK / Accepted), display an error message along with the API response. +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Initiating the Bulk Send has failed" + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +cat $response +echo "" + +batchId=`cat $response | grep batchId | sed 's/.*\"batchId\":\"//' | sed 's/\"}.*//'` + +rm "$response" +rm "$request_data" + +#Step 8: Confirm Bulk Send has initiated. +#Note: Depending on the number of Bulk Recipients, it may take some time for the Bulk Send to complete. For 2000 recipients this can take ~1 hour. + +echo "" +echo "Confirming Bulk Send has initiated. -- ${batchId}" +echo "" + +sleep 10s + +response=$(mktemp /tmp/response-bs.XXXXXX) +Status=$(curl -w '%{http_code}' -i --request GET ${BASE_PATH}/v2.1/accounts/${API_ACCOUNT_ID}/bulk_envelopes/${batchId} \ + "${Headers[@]}" \ + --output ${response}) + +#If the Status code returned is greater than 201 (OK / Accepted), display an error message along with the API response. +if [[ "$Status" -gt "201" ]] ; then + echo "" + echo "Initiating the Bulk Send has failed" + echo "" + cat $response + exit 1 +fi + +echo "" +echo "Response:" +echo "" +cat $response +#Remove the temporary file +rm "$response"