Skip to content

Commit 9c28f10

Browse files
author
nianiB9
committed
bash code for workspaces branding update
1 parent f5b0748 commit 9c28f10

File tree

3 files changed

+179
-83
lines changed

3 files changed

+179
-83
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
# Create a Workspace with an existing brand (Workspaces API only)
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+
# Step 1: Obtain your OAuth token
10+
# Note: Substitute these values with your own
11+
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
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+
17+
# Set the Workspace API base path
18+
base_path="https://api-d.docusign.com/v1"
19+
20+
request_data=$(mktemp /tmp/request-wseg-001.XXXXXX)
21+
response=$(mktemp /tmp/response-wseg-001.XXXXXX)
22+
23+
# Step 2: Retrieve brand_id from config
24+
#ds-snippet-start:Workspaces4Step2
25+
if [[ ! -s config/BRAND_ID ]]; then
26+
echo "No brand_id found. Attempting to run eg028CreatingABrand.sh..."
27+
if [[ -x ./examples/eSignature/eg028CreatingABrand.sh ]]; then
28+
bash ./examples/eSignature/eg028CreatingABrand.sh
29+
else
30+
echo "eg028CreatingABrand.sh not found or not executable."
31+
echo "Please run the eSignature Create a Brand example first."
32+
exit 1
33+
fi
34+
fi
35+
36+
# Re-check after attempt
37+
if [[ ! -s config/BRAND_ID ]]; then
38+
echo "Brand creation did not produce a brand_id. Please create a brand first."
39+
exit 1
40+
fi
41+
brand_id=$(cat config/BRAND_ID)
42+
#ds-snippet-end:Workspaces4Step2
43+
44+
# Step 3: Construct your API headers
45+
#ds-snippet-start:Workspaces4Step3
46+
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
47+
'--header' "Accept: application/json" \
48+
'--header' "Content-Type: application/json")
49+
#ds-snippet-end:Workspaces4Step3
50+
51+
# Step 4: Construct the workspace definition
52+
#ds-snippet-start:Workspaces4Step4
53+
printf \
54+
'{
55+
"name" : "Example workspace",
56+
"brand_id" : "'"${brand_id}"'"
57+
}' >> $request_data
58+
#ds-snippet-end:Workspaces4Step4
59+
60+
# Step 5: Call the Workspaces API
61+
#ds-snippet-start:Workspaces4Step5
62+
Status=$(curl -s -w "%{http_code}\n" -i \
63+
--request POST ${base_path}/accounts/${account_id}/workspaces \
64+
"${Headers[@]}" \
65+
--data-binary @${request_data} \
66+
--output ${response})
67+
#ds-snippet-end:Workspaces4Step5
68+
69+
if [[ "$Status" -gt "201" ]] ; then
70+
echo ""
71+
echo "Failed to create Workspace."
72+
echo ""
73+
cat $response
74+
rm "$response"
75+
rm "$request_data"
76+
exit 0
77+
fi
78+
79+
echo ""
80+
echo "Response:"
81+
cat $response
82+
echo ""
83+
84+
# Pull out the workspace ID and save it
85+
workspace_id=`cat $response | grep workspace_id | sed 's/.*\"workspace_id\":\"//' | sed 's/".*//'`
86+
echo "Workspace created! ID: ${workspace_id}"
87+
echo "Brand used: ${brand_id}"
88+
echo ${workspace_id} > config/WORKSPACE_ID
89+
90+
rm "$response"
91+
rm "$request_data"

examples/eSignature/eg028CreatingABrand.sh

100644100755
Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
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 ""

launcher.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ function startWorkspaces() {
10801080
"Create_Workspace" \
10811081
"Add_Document_To_Workspace" \
10821082
"Send_Envelope_With_Recipient_Info" \
1083+
"Create_Workspace_With_Brand" \
10831084
"Home"; do
10841085
case "$CHOICE" in
10851086

@@ -1098,6 +1099,10 @@ function startWorkspaces() {
10981099
bash examples/Workspaces/eg003SendEnvelopeWithRecipientInfo.sh
10991100
startWorkspaces
11001101
;;
1102+
Create_Workspace_With_Brand)
1103+
bash examples/Workspaces/eg004CreateWorkspaceWithBrand.sh
1104+
startWorkspaces
1105+
;;
11011106
*)
11021107
echo "Default action..."
11031108
startWorkspaces

0 commit comments

Comments
 (0)