|
1 | | -# Creating a brand |
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 | | -read -p "Please enter a new brand name [Sample Bash Corp. {date}]: " BRAND |
9 | | -BRAND=${BRAND:-"Sample Bash Corp. "$(date +%Y-%m-%d-%H:%M)} |
10 | | -export BRAND |
11 | | - |
12 | | - |
13 | | - |
14 | | -# Step 1: Obtain your OAuth token |
15 | | -# Note: Substitute these values with your own |
16 | | -# Set up variables for full code example |
17 | | -ACCESS_TOKEN=$(cat config/ds_access_token.txt) |
18 | | -account_id=$(cat config/API_ACCOUNT_ID) |
19 | | -base_path="https://demo.docusign.net/restapi" |
20 | | - |
21 | | -# Step 2: Construct your API headers |
22 | | -#ds-snippet-start:eSign28Step2 |
23 | | -declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ |
24 | | - '--header' "Accept: application/json" \ |
25 | | - '--header' "Content-Type: application/json") |
26 | | -#ds-snippet-end:eSign28Step2 |
27 | | - |
28 | | -# Step 3: Construct the request body |
29 | | -# Create a temporary file to store the request body |
30 | | -request_data=$(mktemp /tmp/request-brand-001.XXXXXX) |
31 | | -#ds-snippet-start:eSign28Step3 |
32 | | -printf \ |
33 | | -'{ |
34 | | -
|
35 | | - "brandName": "'"${BRAND}"'", |
36 | | - "defaultBrandLanguage": "en" |
37 | | -
|
38 | | -}' >> $request_data |
39 | | -#ds-snippet-end:eSign28Step3 |
40 | | - |
41 | | -# Step 4: a) Call the eSignature API |
42 | | -# b) Display the JSON response |
43 | | -# Create a temporary file to store the response |
44 | | -response=$(mktemp /tmp/response-brand.XXXXXX) |
45 | | - |
46 | | -#ds-snippet-start:eSign28Step4 |
47 | | -Status=$(curl -w '%{http_code}' -i --request POST ${base_path}/v2.1/accounts/${account_id}/brands \ |
48 | | - "${Headers[@]}" \ |
49 | | - --data-binary @${request_data} \ |
50 | | - --output ${response}) |
51 | | -#ds-snippet-end:eSign28Step4 |
52 | | - |
53 | | -# If the Status code returned is greater than 399, display an error message along with the API response |
54 | | -if [[ "$Status" -gt "399" ]] ; then |
55 | | - echo "" |
56 | | - echo "Creating a new brand has failed." |
57 | | - echo "" |
58 | | - cat $response |
59 | | - exit 0 |
60 | | -fi |
61 | | - |
62 | | - |
63 | | -# Retrieve the profile ID from the API response. |
64 | | -brandId=`cat $response | grep brandId | sed 's/.*\"brandId\":\"//' | sed 's/\",.*//'` |
65 | | -# Save the envelope id for use by other scripts |
66 | | -echo "brand Id: ${brandId}" |
67 | | -echo ${brandId} > config/BRAND_ID |
68 | | - |
69 | | - |
70 | | -echo "" |
71 | | -echo "Response:" |
72 | | -cat $response |
73 | | -echo "" |
74 | | - |
75 | | -# Remove the temporary files |
76 | | -rm "$request_data" |
77 | | -rm "$response" |
78 | | - |
79 | | -echo "" |
80 | | -echo "" |
81 | | -echo "Done." |
82 | | -echo "" |
83 | | - |
| 1 | +#!/bin/bash |
| 2 | +# Creating a brand |
| 3 | +# |
| 4 | +# Check that we're in a bash shell |
| 5 | +if [[ $SHELL != *"bash"* ]]; then |
| 6 | + echo "PROBLEM: Run these scripts from within the bash shell." |
| 7 | +fi |
| 8 | + |
| 9 | +read -p "Please enter a new brand name [Sample Bash Corp. {date}]: " BRAND |
| 10 | +BRAND=${BRAND:-"Sample Bash Corp. "$(date +%Y-%m-%d-%H:%M)} |
| 11 | +export BRAND |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +# Step 1: Obtain your OAuth token |
| 16 | +# Note: Substitute these values with your own |
| 17 | +# Set up variables for full code example |
| 18 | +ACCESS_TOKEN=$(cat config/ds_access_token.txt) |
| 19 | +account_id=$(cat config/API_ACCOUNT_ID) |
| 20 | +base_path="https://demo.docusign.net/restapi" |
| 21 | + |
| 22 | +# Step 2: Construct your API headers |
| 23 | +#ds-snippet-start:eSign28Step2 |
| 24 | +declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \ |
| 25 | + '--header' "Accept: application/json" \ |
| 26 | + '--header' "Content-Type: application/json") |
| 27 | +#ds-snippet-end:eSign28Step2 |
| 28 | + |
| 29 | +# Step 3: Construct the request body |
| 30 | +# Create a temporary file to store the request body |
| 31 | +request_data=$(mktemp /tmp/request-brand-001.XXXXXX) |
| 32 | +#ds-snippet-start:eSign28Step3 |
| 33 | +printf \ |
| 34 | +'{ |
| 35 | +
|
| 36 | + "brandName": "'"${BRAND}"'", |
| 37 | + "defaultBrandLanguage": "en" |
| 38 | +
|
| 39 | +}' >> $request_data |
| 40 | +#ds-snippet-end:eSign28Step3 |
| 41 | + |
| 42 | +# Step 4: a) Call the eSignature API |
| 43 | +# b) Display the JSON response |
| 44 | +# Create a temporary file to store the response |
| 45 | +response=$(mktemp /tmp/response-brand.XXXXXX) |
| 46 | + |
| 47 | +#ds-snippet-start:eSign28Step4 |
| 48 | +Status=$(curl -w '%{http_code}' -i --request POST ${base_path}/v2.1/accounts/${account_id}/brands \ |
| 49 | + "${Headers[@]}" \ |
| 50 | + --data-binary @${request_data} \ |
| 51 | + --output ${response}) |
| 52 | +#ds-snippet-end:eSign28Step4 |
| 53 | + |
| 54 | +# If the Status code returned is greater than 399, display an error message along with the API response |
| 55 | +if [[ "$Status" -gt "399" ]] ; then |
| 56 | + echo "" |
| 57 | + echo "Creating a new brand has failed." |
| 58 | + echo "" |
| 59 | + cat $response |
| 60 | + exit 0 |
| 61 | +fi |
| 62 | + |
| 63 | + |
| 64 | +# Retrieve the profile ID from the API response. |
| 65 | +brandId=`cat $response | grep brandId | sed 's/.*\"brandId\":\"//' | sed 's/\",.*//'` |
| 66 | +# Save the envelope id for use by other scripts |
| 67 | +echo "brand Id: ${brandId}" |
| 68 | +echo ${brandId} > config/BRAND_ID |
| 69 | + |
| 70 | + |
| 71 | +echo "" |
| 72 | +echo "Response:" |
| 73 | +cat $response |
| 74 | +echo "" |
| 75 | + |
| 76 | +# Remove the temporary files |
| 77 | +rm "$request_data" |
| 78 | +rm "$response" |
| 79 | + |
| 80 | +echo "" |
| 81 | +echo "" |
| 82 | +echo "Done." |
| 83 | +echo "" |
0 commit comments