11#! /bin/bash
2- # Create a workspace upload request
2+ # Send an Workspace Envelope with Recipient Info
33#
44# Check that we're in a bash shell
55if [[ $SHELL != * " bash" * ]]; then
@@ -13,6 +13,13 @@ if [ -z "$workspace_id" ]; then
1313 exit 0
1414fi
1515
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 create a workspace before running this example"
20+ exit 0
21+ fi
22+
1623# Step 1: Obtain your OAuth token
1724# Note: Substitute these values with your own
1825ACCESS_TOKEN=$( cat config/ds_access_token.txt)
@@ -24,7 +31,6 @@ account_id=$(cat config/API_ACCOUNT_ID)
2431# Set the Workspace API base path
2532base_path=" https://api-d.docusign.com/v1"
2633
27- workspace_data_response=$( mktemp /tmp/response-ws-data.XXXXXX)
2834request_data=$( mktemp /tmp/request-wseg-001.XXXXXX)
2935response=$( mktemp /tmp/response-wseg-001.XXXXXX)
3036
3945fi
4046
4147# 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
48+ # ds-snippet-start:Workspaces4Step2
4349declare -a Headers=(' --header' " Authorization: Bearer ${ACCESS_TOKEN} " \
4450 ' --header' " Accept: application/json" \
4551 ' --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-
52+ # ds-snippet-end:Workspaces4Step2
7253
7354# Create the workspace upload request definition
7455# apx-snippet-start:createWorkspaceUploadRequest
75- # ds-snippet-start:Workspaces5Step3
56+ # ds-snippet-start:Workspaces4Step3
7657printf \
7758' {
7859 "name": "Upload Request example ' " ${DUE_DATE} " ' ",
@@ -86,21 +67,21 @@ printf \
8667 "email": "' " ${SIGNER_EMAIL} " ' "
8768 },
8869 {
89- "assignee_user_id": "' " ${WORKSPACE_CREATOR_ID } " ' ",
70+ "assignee_user_id": "' " ${workspace_creator_id } " ' ",
9071 "upload_request_responsibility_type_id": "watcher"
9172 }
9273 ],
9374 "status": "draft"
9475}' >> $request_data
95- # ds-snippet-end:Workspaces5Step3
76+ # ds-snippet-end:Workspaces4Step3
9677
97- # ds-snippet-start:Workspaces5Step4
78+ # ds-snippet-start:Workspaces4Step4
9879Status=$( curl -s -w " %{http_code}\n" -i \
9980 --request POST ${base_path} /accounts/${account_id} /workspaces/${workspace_id} /upload-requests \
10081 " ${Headers[@]} " \
10182 --data-binary @${request_data} \
10283 --output ${response} )
103- # ds-snippet-end:Workspaces5Step4
84+ # ds-snippet-end:Workspaces4Step4
10485# apx-snippet-end:createWorkspaceUploadRequest
10586
10687if [[ " $Status " -gt " 201" ]] ; then
@@ -124,3 +105,4 @@ echo "Workspace upload request created! ID: ${upload_request_id}"
124105rm " $response "
125106rm " $request_data "
126107
108+
0 commit comments