Skip to content

Commit bead705

Browse files
Add files via upload
Signed-off-by: CassandraLoewen <[email protected]>
1 parent 0edc098 commit bead705

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/bash
2+
# Send an Workspace Envelope with Recipient Info
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+
# Check that a workspace exists
10+
workspace_id=$(cat config/WORKSPACE_ID)
11+
if [ -z "$workspace_id" ]; then
12+
echo "Please create a workspace before running this example"
13+
exit 0
14+
fi
15+
16+
# Step 1: Obtain your OAuth token
17+
# Note: Substitute these values with your own
18+
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
19+
20+
# Set up variables for full code example
21+
# Note: Substitute these values with your own
22+
account_id=$(cat config/API_ACCOUNT_ID)
23+
24+
#Set the Workspace API base path
25+
base_path="https://api-d.docusign.com/v1"
26+
27+
workspace_data_response=$(mktemp /tmp/response-ws-data.XXXXXX)
28+
request_data=$(mktemp /tmp/request-wseg-001.XXXXXX)
29+
response=$(mktemp /tmp/response-wseg-001.XXXXXX)
30+
31+
# Calculate ISO 8601 date 7 days from now
32+
# Uses 'date -v +7d' on macOS or 'date -d "+7 days"' on Linux (GNU date)
33+
if date -v +1d > /dev/null 2>&1; then
34+
# macOS/BSD 'date'
35+
DUE_DATE=$(date -v +7d "+%Y-%m-%dT%H:%M:%SZ")
36+
else
37+
# Linux (GNU 'date')
38+
DUE_DATE=$(date -d "+7 days" "+%Y-%m-%dT%H:%M:%SZ")
39+
fi
40+
41+
# This header will be used for both the API call to get the ID of the workspace creator, and to create the upload request
42+
#ds-snippet-start:Workspaces5Step2
43+
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
44+
'--header' "Accept: application/json" \
45+
'--header' "Content-Type: application/json")
46+
#ds-snippet-end:Workspaces5Step2
47+
48+
49+
# Prepare to make GET API call to return the data of the workspace and extract the ID of the workspace creator"
50+
Status=$(curl -s -w "%{http_code}" \
51+
--request GET "${base_path}/accounts/${account_id}/workspaces/${workspace_id}" \
52+
"${Headers[@]}" \
53+
--output "${workspace_data_response}")
54+
55+
# "Check to see if an error was thrown getting data on the workspace"
56+
if [[ "$Status" != "200" ]]; then
57+
echo "An error was thrown getting the ID of the workspace creator. HTTP Status: $Status"
58+
echo "Response content:"
59+
cat "$workspace_data_response"
60+
rm "$workspace_data_response"
61+
exit 1
62+
fi
63+
64+
# Find the ID of the user who created the workspace
65+
if [[ "$Status" == "200" ]]; then
66+
67+
WORKSPACE_CREATOR_ID=$(grep -o -m 1 '"created_by_user_id":"[^"]*"' "$workspace_data_response" | \
68+
sed 's/.*"created_by_user_id":"\([^"]*\)".*/\1/')
69+
echo "The ID of the workspace creator is $WORKSPACE_CREATOR_ID"
70+
fi
71+
72+
73+
# Create the workspace upload request definition
74+
#apx-snippet-start:createWorkspaceUploadRequest
75+
#ds-snippet-start:Workspaces5Step3
76+
printf \
77+
'{
78+
"name": "Upload Request example '"${DUE_DATE}"'",
79+
"description": "This is an example upload request created via the workspaces API",
80+
"due_date": "'"${DUE_DATE}"'",
81+
"assignments": [
82+
{
83+
"upload_request_responsibility_type_id": "assignee",
84+
"first_name": "Test",
85+
"last_name": "User",
86+
"email": "'"${SIGNER_EMAIL}"'"
87+
},
88+
{
89+
"assignee_user_id": "'"${WORKSPACE_CREATOR_ID}"'",
90+
"upload_request_responsibility_type_id": "watcher"
91+
}
92+
],
93+
"status": "draft"
94+
}' >> $request_data
95+
#ds-snippet-end:Workspaces5Step3
96+
97+
#ds-snippet-start:Workspaces5Step4
98+
Status=$(curl -s -w "%{http_code}\n" -i \
99+
--request POST ${base_path}/accounts/${account_id}/workspaces/${workspace_id}/upload-requests \
100+
"${Headers[@]}" \
101+
--data-binary @${request_data} \
102+
--output ${response})
103+
#ds-snippet-end:Workspaces5Step4
104+
#apx-snippet-end:createWorkspaceUploadRequest
105+
106+
if [[ "$Status" -gt "201" ]] ; then
107+
echo ""
108+
echo "Failed to create Workspace upload request."
109+
echo ""
110+
cat $Status
111+
cat $response
112+
exit 0
113+
fi
114+
115+
echo ""
116+
echo "Response:"
117+
cat $response
118+
echo ""
119+
120+
# Get the workspace upload request ID and display it
121+
upload_request_id=`cat $response | grep upload_request_id | sed 's/.*\"upload_request_id\":\"//' | sed 's/".*//'`
122+
echo "Workspace upload request created! ID: ${upload_request_id}"
123+
124+
rm "$response"
125+
rm "$request_data"

0 commit comments

Comments
 (0)