|
| 1 | +#!/bin/bash |
| 2 | +# https://developers.docusign.com/docs/admin-api/how-to/create-active-user/ |
| 3 | +# How to create a new user with active status |
| 4 | +# |
| 5 | +# Check that we're in a bash shell |
| 6 | +if [[ $SHELL != *"bash"* ]]; then |
| 7 | + echo "PROBLEM: Run these scripts from within the bash shell." |
| 8 | +fi |
| 9 | + |
| 10 | +# Note: Substitute these values with your own |
| 11 | +# Obtain your OAuth token |
| 12 | +ACCESS_TOKEN=$(cat config/ds_access_token.txt) |
| 13 | + |
| 14 | +# Set up variables for full code example |
| 15 | +# Note: Substitute these values with your own |
| 16 | +API_ACCOUNT_ID=$(cat config/API_ACCOUNT_ID) |
| 17 | +base_path="https://api-d.docusign.net/management" |
| 18 | +ORGANIZATION_ID=$(cat config/ORGANIZATION_ID) |
| 19 | + |
| 20 | +# Construct your API headers |
| 21 | +#ds-snippet-start:Admin13Step2 |
| 22 | +declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" |
| 23 | + '--header' "Accept: application/json" |
| 24 | + '--header' "Content-Type: application/json") |
| 25 | +#ds-snippet-end:Admin13Step2 |
| 26 | + |
| 27 | +#ds-snippet-start:Admin13Step3 |
| 28 | +response=$(mktemp /tmp/response-oa.XXXXXX) |
| 29 | +Status=$(curl --request GET ${base_path}/v2/organizations/${ORGANIZATION_ID}/planItems \ |
| 30 | +"${Headers[@]}" \ |
| 31 | +--output ${response}) |
| 32 | + |
| 33 | +echo "Results from the GET request:" |
| 34 | +cat $response |
| 35 | +echo "" |
| 36 | + |
| 37 | +PLAN_ID=$(cat $response | sed 's/,/\n/g' | grep plan_id | sed 's/.*\"plan_id\":\"//g' | sed 's/\".*//g') |
| 38 | +SUBSCRIPTION_ID=$(cat $response | sed 's/,/\n/g' | grep subscription_id | sed 's/.*\"subscription_id\":\"//g' | sed 's/\".*//g') |
| 39 | +#ds-snippet-end:Admin13Step3 |
| 40 | + |
| 41 | +request_data=$(mktemp /tmp/request_data-oa.XXXXXX) |
| 42 | + |
| 43 | +read -p "Please enter the account name for the new account: " ACCOUNT_NAME |
| 44 | +read -p "Please enter the email address for the new account: " EMAIL_ADDRESS |
| 45 | +read -p "Please enter the first name for the new account: " FIRST_NAME |
| 46 | +read -p "Please enter the last name for the new account: " LAST_NAME |
| 47 | + |
| 48 | +#ds-snippet-start:Admin13Step4 |
| 49 | +# The country code value is set to "US" for the developer environment |
| 50 | +# In production, set the value to the code for the country of the target account |
| 51 | +printf \ |
| 52 | +'{ |
| 53 | + "subscriptionDetails": { |
| 54 | + "id": "'${SUBSCRIPTION_ID}'", |
| 55 | + "planId": "'${PLAN_ID}'", |
| 56 | + "modules": [] |
| 57 | + }, |
| 58 | + "targetAccount": { |
| 59 | + "name": "'${ACCOUNT_NAME}'", |
| 60 | + "countryCode": "US", |
| 61 | + "admin": { |
| 62 | + "email": "'${EMAIL_ADDRESS}'", |
| 63 | + "firstName": "'${FIRST_NAME}'", |
| 64 | + "lastName": "'${LAST_NAME}'", |
| 65 | + "locale": "en" |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +' >>$request_data |
| 70 | +#ds-snippet-end:Admin13Step4 |
| 71 | + |
| 72 | +# Create the new account |
| 73 | +#ds-snippet-start:Admin13Step5 |
| 74 | +response=$(mktemp /tmp/response-oa.XXXXXX) |
| 75 | +Status=$(curl --request POST ${base_path}/v2/organizations/${ORGANIZATION_ID}/assetGroups/accountCreate \ |
| 76 | +"${Headers[@]}" \ |
| 77 | +--data-binary @${request_data} \ |
| 78 | +--output ${response}) |
| 79 | +#ds-snippet-end:Admin13Step5 |
| 80 | + |
| 81 | +echo "Results from the create account method:" |
| 82 | +cat $response |
| 83 | +echo "" |
| 84 | + |
| 85 | +# Remove the temporary files |
| 86 | +rm "$response" |
| 87 | +rm "$request_data" |
| 88 | +echo "" |
| 89 | +echo "Done." |
0 commit comments