|
| 1 | +# Check that we're in a bash shell |
| 2 | +if [[ $SHELL != *"bash"* ]]; then |
| 3 | + echo "PROBLEM: Run these scripts from within the bash shell." |
| 4 | +fi |
| 5 | + |
| 6 | +ds_access_token_path="config/ds_access_token.txt" |
| 7 | +agreements="config/AGREEMENTS.txt" |
| 8 | + |
| 9 | +# Obtain your OAuth token |
| 10 | +# Note: Substitute these values with your own |
| 11 | +ACCESS_TOKEN=$(cat ${ds_access_token_path}) |
| 12 | + |
| 13 | +# Set up variables for full code example |
| 14 | +# Note: Substitute these values with your own |
| 15 | +ACCOUNT_ID=$(cat config/API_ACCOUNT_ID) |
| 16 | +base_path="https://api-d.docusign.com/v1" |
| 17 | + |
| 18 | +# Check if agreements file exists and has content |
| 19 | +if [[ ! -s "$agreements" ]]; then |
| 20 | + echo "Please run Navigator example 1: List_Agreements first to get a list of agreements." |
| 21 | + exit 0 |
| 22 | +fi |
| 23 | + |
| 24 | +#Display list of agreements |
| 25 | +# Initialize an array to hold the file_names |
| 26 | +file_names=() |
| 27 | + |
| 28 | +# Read each line from AGREEMENTS.txt and populate file_names array |
| 29 | +while IFS=' ' read -r id file_name; do |
| 30 | + file_names+=("$file_name") |
| 31 | +done < $agreements |
| 32 | + |
| 33 | +# Display the file_name options to the user for selection |
| 34 | +echo "Please select an agreement:" |
| 35 | +select chosen_name in "${file_names[@]}"; do |
| 36 | + if [[ -n "$chosen_name" ]]; then |
| 37 | + # Find the matching line and extract the corresponding id |
| 38 | + AGREEMENT_ID=$(grep -w "$chosen_name" "$agreements" | awk '{print $1}') |
| 39 | + echo "You selected: $chosen_name" |
| 40 | + echo "AGREEMENT_ID: $AGREEMENT_ID" |
| 41 | + break |
| 42 | + else |
| 43 | + echo "Invalid selection. Please try again." |
| 44 | + fi |
| 45 | +done |
| 46 | + |
| 47 | +#ds-snippet-start:Navigator2Step2 |
| 48 | +declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ |
| 49 | + '--header' "Accept: application/json" \ |
| 50 | + '--header' "Content-Type: application/json") |
| 51 | +#ds-snippet-end:Navigator2Step2 |
| 52 | + |
| 53 | +# Get Agreement |
| 54 | +#ds-snippet-start:Navigator2Step3 |
| 55 | +response=$(mktemp /tmp/response-neg-002.XXXXXX) |
| 56 | +Status=$(curl -w '%{http_code}' -i --request GET ${base_path}/accounts/${ACCOUNT_ID}/agreements/${AGREEMENT_ID} \ |
| 57 | + "${Headers[@]}" \ |
| 58 | + --output ${response}) |
| 59 | +#ds-snippet-end:Navigator2Step3 |
| 60 | + |
| 61 | + |
| 62 | +if [[ "$Status" -gt "399" ]] ; then |
| 63 | + echo "" |
| 64 | + echo "Error: " |
| 65 | + echo "" |
| 66 | + cat $response |
| 67 | + exit 0 |
| 68 | +fi |
| 69 | + |
| 70 | +echo "" |
| 71 | +echo "Response:" |
| 72 | +cat $response |
| 73 | +echo "" |
| 74 | + |
| 75 | + |
| 76 | +# Remove the temporary files |
| 77 | +rm "$response" |
0 commit comments