Skip to content

Commit 87f2aab

Browse files
author
nianiB9
committed
2 parents ad95319 + 00fadf4 commit 87f2aab

File tree

3 files changed

+122
-3
lines changed

3 files changed

+122
-3
lines changed

examples/Workspaces/eg001CreateWorkspace.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Send an Workspace Envelope with Recipient Info
2+
# Create a workspace
33
#
44
# Check that we're in a bash shell
55
if [[ $SHELL != *"bash"* ]]; then
@@ -59,8 +59,11 @@ echo ""
5959

6060
# Pull out the workspace ID and save it
6161
workspace_id=`cat $response | grep workspace_id | sed 's/.*\"workspace_id\":\"//' | sed 's/".*//'`
62-
echo "Workspace created! ID: ${workspace_id}"
62+
workspace_creator_id=$(grep -o -m 1 '"created_by_user_id":"[^"]*"' "$response" | \
63+
sed 's/.*"created_by_user_id":"\([^"]*\)".*/\1/')
64+
echo "Workspace created by user ${workspace_creator_id}! Workspace ID: ${workspace_id}"
6365
echo ${workspace_id} > config/WORKSPACE_ID
66+
echo ${workspace_creator_id} > config/WORKSPACE_CREATOR_ID
6467

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

launcher.sh

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

@@ -1103,6 +1104,10 @@ function startWorkspaces() {
11031104
bash examples/Workspaces/eg004CreateWorkspaceWithBrand.sh
11041105
startWorkspaces
11051106
;;
1107+
Create_Upload_Request)
1108+
bash examples/Workspaces/eg005CreateUploadRequest.sh
1109+
startWorkspaces
1110+
;;
11061111
*)
11071112
echo "Default action..."
11081113
startWorkspaces

0 commit comments

Comments
 (0)