|
| 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 | + |
0 commit comments