Skip to content

Commit f326ab1

Browse files
karissarjacobsenCassandraLoewennianiB9nianiB9
authored
Workspaces API set up (#113)
* Workspaces API set up * added full code example * Adding Create Workspace code draft * add codeDepot tags * codeDepot tags * add doc to workspace (#119) Co-authored-by: nianiB9 <[email protected]> * code snippets --------- Co-authored-by: Cassandra Loewen <[email protected]> Co-authored-by: CassandraLoewen <[email protected]> Co-authored-by: nianiB9 <[email protected]> Co-authored-by: nianiB9 <[email protected]>
1 parent 6b579ae commit f326ab1

File tree

7 files changed

+345
-0
lines changed

7 files changed

+345
-0
lines changed

OAuth/code_grant.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
$scope = "signature aow_manage";
3333
elseif($api_version == "Navigator") :
3434
$scope = "signature adm_store_unified_repo_read";
35+
elseif($api_version == "Workspaces") :
36+
$scope = "signature impersonation dtr.company.read dtr.rooms.read dtr.rooms.write dtr.documents.write";
3537
endif;
3638

3739
function generateCodeVerifier() {

OAuth/jwt.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
$scope = "signature adm_store_unified_repo_read";
3838
} else if ($api_version == "ConnectedFields") {
3939
$scope = "signature adm_store_unified_repo_read";
40+
} else if ($api_version == "Workspaces") {
41+
$scope = "signature impersonation dtr.company.read dtr.rooms.read dtr.rooms.write dtr.documents.write";
4042
}
4143

4244
$body = encodeBase64URL(

OAuth/jwt_auth.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
"signature", "adm_store_unified_repo_read"
6969
]
7070

71+
WORKSPACES_SCOPES = [
72+
"signature", "impersonation", "dtr.company.read", "dtr.rooms.read", "dtr.rooms.write", "dtr.documents.write"
73+
]
74+
7175
class DSClient:
7276

7377
ds_app = None
@@ -95,6 +99,8 @@ def _jwt_auth(cls):
9599
use_scopes = NAVIGATOR_SCOPES
96100
elif (API_VERSION == "ConnectedFields"):
97101
use_scopes = CONNECTED_FIELDS_SCOPES
102+
elif (API_VERSION == "Workspaces"):
103+
use_scopes = WORKSPACES_SCOPES
98104
else:
99105
use_scopes = SCOPES
100106

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# https://developers.docusign.com/docs/workflows-api/trigger-workflow
3+
# Send an Workspace Envelope with Recipient Info
4+
#
5+
# Check that we're in a bash shell
6+
if [[ $SHELL != *"bash"* ]]; then
7+
echo "PROBLEM: Run these scripts from within the bash shell."
8+
fi
9+
10+
# Step 1: Obtain your OAuth token
11+
# Note: Substitute these values with your own
12+
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
13+
14+
# Set up variables for full code example
15+
# Note: Substitute these values with your own
16+
account_id=$(cat config/API_ACCOUNT_ID)
17+
18+
#Set the Workspace API base path
19+
base_path="https://api-d.docusign.com/v1"
20+
21+
request_data=$(mktemp /tmp/request-wseg-001.XXXXXX)
22+
response=$(mktemp /tmp/response-wseg-001.XXXXXX)
23+
24+
#ds-snippet-start:Workflows1Step2
25+
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
26+
'--header' "Accept: application/json" \
27+
'--header' "Content-Type: application/json")
28+
#ds-snippet-end:Workflows1Step2
29+
30+
# Create the workspace definition
31+
#ds-snippet-start:Workflows1Step3
32+
printf \
33+
'{
34+
"name" : "Example workspace"
35+
}' >> $request_data
36+
#ds-snippet-end:Workflows1Step3
37+
38+
#ds-snippet-start:Workflows1Step4
39+
Status=$(curl -s -w "%{http_code}\n" -i \
40+
--request POST ${base_path}/accounts/${account_id}/workspaces \
41+
"${Headers[@]}" \
42+
--data-binary @${request_data} \
43+
--output ${response})
44+
#ds-snippet-end:Workflows1Step4
45+
46+
if [[ "$Status" -gt "201" ]] ; then
47+
echo ""
48+
echo "Failed to create Workspace."
49+
echo ""
50+
cat $response
51+
exit 0
52+
fi
53+
54+
echo ""
55+
echo "Response:"
56+
cat $response
57+
echo ""
58+
59+
# Pull out the workspace ID and save it
60+
workspace_id=`cat $response | grep workspace_id | sed 's/.*\"workspace_id\":\"//' | sed 's/".*//'`
61+
echo "Workspace created! ID: ${workspace_id}"
62+
echo ${workspace_id} > config/WORKSPACE_ID
63+
64+
rm "$response"
65+
rm "$request_data"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
# https://developers.docusign.com/docs/workspaces-api
3+
# Add a document to a Workspace
4+
#
5+
# Check that we're in a bash shell
6+
if [[ $SHELL != *"bash"* ]]; then
7+
echo "PROBLEM: Run these scripts from within the bash shell."
8+
fi
9+
10+
# Check that a workspace exists
11+
workspace_id=$(cat config/WORKSPACE_ID)
12+
if [ -z "$workspace_id" ]; then
13+
echo "Please create a workspace before running this example"
14+
exit 0
15+
fi
16+
17+
# Step 1: Obtain your OAuth token
18+
# Note: Substitute these values with your own
19+
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
20+
21+
# Set up variables for full code example
22+
# Note: Substitute these values with your own
23+
account_id=$(cat config/API_ACCOUNT_ID)
24+
25+
# Set the Workspace API base path
26+
base_path="https://api-d.docusign.com/v1"
27+
28+
29+
response=$(mktemp /tmp/response-wseg-002.XXXXXX)
30+
31+
#ds-snippet-start:Workflows2Step2
32+
declare -a Headers=(
33+
--header "Authorization: Bearer ${ACCESS_TOKEN}"
34+
--header "Accept: application/json"
35+
)
36+
#ds-snippet-end:Workflows2Step2
37+
38+
39+
# Upload the file path to be added to the workspace
40+
#ds-snippet-start:Workflows2Step3
41+
echo ""
42+
echo "Enter the path to the document you want to add to the workspace:"
43+
echo ""
44+
read file_path
45+
46+
if [ ! -f "$file_path" ]; then
47+
echo "File does not exist: $file_path"
48+
exit 1
49+
fi
50+
51+
# Enter the document name for the workspace
52+
echo ""
53+
echo "Enter the name for the document in the workspace:"
54+
echo ""
55+
56+
read doc_name
57+
#ds-snippet-end:Workflows2Step3
58+
59+
#ds-snippet-start:Workflows2Step4
60+
Status=$(curl -s -w "%{http_code}" -o "${response}" \
61+
--request POST "${base_path}/accounts/${account_id}/workspaces/${workspace_id}/documents" \
62+
"${Headers[@]}" \
63+
-F "file=@${file_path}" \
64+
-F "name=${doc_name}"
65+
)
66+
#ds-snippet-end:Workflows2Step4
67+
68+
69+
if [[ "$Status" -gt "201" ]]; then
70+
echo ""
71+
echo "Failed to add document to workspace."
72+
echo ""
73+
cat $response
74+
rm "$response"
75+
exit 0
76+
fi
77+
78+
echo ""
79+
echo "Response:"
80+
cat $response
81+
echo ""
82+
83+
# Pull out the document ID and save it
84+
document_id=$(cat $response | grep document_id | sed 's/.*"document_id":"//' | sed 's/".*//')
85+
echo "Document added! ID: ${document_id}"
86+
echo ${document_id} > config/DOCUMENT_ID
87+
88+
rm "$response"
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/bin/bash
2+
# https://developers.docusign.com/docs/workflows-api/trigger-workflow
3+
# Send an Workspace Envelope with Recipient Info
4+
#
5+
# Check that we're in a bash shell
6+
if [[ $SHELL != *"bash"* ]]; then
7+
echo "PROBLEM: Run these scripts from within the bash shell."
8+
fi
9+
10+
#check that a workspace exists
11+
workspace_id=$(cat config/WORKSPACE_ID)
12+
if [ -z "$workspace_id" ]; then
13+
echo "please create a workspace before running this example"
14+
exit 0
15+
fi
16+
17+
#check that a document exists in the workspace
18+
document_id=$(cat config/DOCUMENT_ID)
19+
if [ -z "$workspace_id" ]; then
20+
echo "please create a document in the workspace before running this example"
21+
exit 0
22+
fi
23+
24+
# Step 1: Obtain your OAuth token
25+
# Note: Substitute these values with your own
26+
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
27+
28+
29+
# Set up variables for full code example
30+
# Note: Substitute these values with your own
31+
account_id=$(cat config/API_ACCOUNT_ID)
32+
33+
#Set the Workspace API base path
34+
base_path="https://api-d.docusign.com/v1"
35+
36+
request_data=$(mktemp /tmp/request-wseg-001.XXXXXX)
37+
response=$(mktemp /tmp/response-wseg-001.XXXXXX)
38+
39+
#ds-snippet-start:Workflows3Step2
40+
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
41+
'--header' "Accept: application/json" \
42+
'--header' "Content-Type: application/json")
43+
#ds-snippet-end:Workflows3Step2
44+
45+
# Create the workspace envelope definition
46+
#ds-snippet-start:Workflows3Step3
47+
printf \
48+
'{
49+
"envelope_name": "Example Workspace Envelope",
50+
"document_ids": ["'"${document_id}"'"]
51+
}' >> $request_data
52+
#ds-snippet-end:Workflows3Step3
53+
54+
#ds-snippet-start:Workflows3Step4
55+
Status=$(curl -s -w "%{http_code}\n" -i \
56+
--request POST ${base_path}/accounts/${account_id}/workspaces/${workspace_id}/envelopes \
57+
"${Headers[@]}" \
58+
--data-binary @${request_data} \
59+
--output ${response})
60+
#ds-snippet-end:Workflows3Step4
61+
62+
if [[ "$Status" -gt "201" ]] ; then
63+
echo ""
64+
echo "Failed to send envelope."
65+
echo ""
66+
cat $response
67+
exit 0
68+
fi
69+
70+
echo ""
71+
echo "Response:"
72+
cat $response
73+
echo ""
74+
75+
# pull out the envelope_id
76+
envelope_id=`cat $response | grep envelope_id | sed 's/.*\"envelope_id\":\"//' | sed 's/".*//'`
77+
echo "Envelope created! ID: ${envelope_id}"
78+
79+
rm "$response"
80+
rm "$request_data"
81+
request_data=$(mktemp /tmp/request2-wseg-001.XXXXXX)
82+
response=$(mktemp /tmp/response2-wseg-001.XXXXXX)
83+
84+
#Set the eSignature REST API base path
85+
base_path="https://demo.docusign.net/restapi"
86+
87+
#ds-snippet-start:Workflows3Step5
88+
printf \
89+
'{
90+
"emailSubject": "Please sign this document",
91+
"recipients": {
92+
"signers": [
93+
{
94+
"email": "'"${SIGNER_EMAIL}"'",
95+
"name": "'"${SIGNER_NAME}"'",
96+
"recipientId": "1",
97+
"routingOrder": "1",
98+
"tabs": {
99+
"signHereTabs": [
100+
{
101+
"anchorString": "/sn1/",
102+
"anchorUnits": "pixels",
103+
"anchorXOffset": "20",
104+
"anchorYOffset": "10"
105+
}
106+
]
107+
}
108+
}
109+
]
110+
},
111+
"status": "sent"
112+
}' >> $request_data
113+
#ds-snippet-end:Workflows3Step5
114+
115+
#ds-snippet-start:Workflows3Step6
116+
Status=$(curl -s -o "${response}" -w "%{http_code}" \
117+
--request PUT "${base_path}/v2.1/accounts/${account_id}/envelopes/${envelope_id}" \
118+
"${Headers[@]}" \
119+
--data-binary @"${request_data}")
120+
#ds-snippet-end:Workflows3Step6
121+
122+
if [[ "$Status" -gt "201" ]] ; then
123+
echo ""
124+
echo "Failed to send envelope."
125+
echo ""
126+
cat $response
127+
exit 0
128+
fi
129+
130+
echo ""
131+
echo "Response:"
132+
cat $response
133+
echo ""
134+
echo ""
135+
echo "Envelope Sent!"
136+
echo ""
137+
138+
rm "$response"
139+
rm "$request_data"

0 commit comments

Comments
 (0)