Skip to content

Commit 42cc5ae

Browse files
authored
Account creation (#93)
* research work for how to create an account through the API * updating account creation method * adding codeDepot markers * additional user input * fixing scopes for JWT PHP
1 parent ec8a123 commit 42cc5ae

File tree

5 files changed

+98
-3
lines changed

5 files changed

+98
-3
lines changed

OAuth/code_grant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
echo "Auth Code Grant is not supported for the Monitor API.";
2222
$scope = "signature impersonation";
2323
elseif($api_version == "Admin") :
24-
$scope = 'signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read user_data_redact asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read';
24+
$scope = 'signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read user_data_redact asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read organization_sub_account_write organization_sub_account_read';
2525
elseif($api_version == "Notary") :
2626
$scope = "signature organization_read notary_read notary_write";
2727
elseif($api_version == "WebForms") :

OAuth/jwt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
} else if ($api_version == "Monitor") {
2727
$scope = "signature impersonation";
2828
} else if ($api_version == "Admin") {
29-
$scope = 'signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read impersonation user_data_redact asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read';
29+
$scope = 'signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read impersonation user_data_redact asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read organization_sub_account_read organization_sub_account_write';
3030
} else if ($api_version == "Notary") {
3131
$scope = "signature organization_read notary_read notary_write";
3232
} else if ($api_version == "WebForms") {

OAuth/jwt_auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"signature", "organization_read", "group_read", "permission_read",
4545
"user_read", "user_write", "account_read", "domain_read",
4646
"identity_provider_read", "user_data_redact", "asset_group_account_read",
47-
"asset_group_account_clone_write", "asset_group_account_clone_read"
47+
"asset_group_account_clone_write", "asset_group_account_clone_read",
48+
"organization_sub_account_write", "organization_sub_account_read"
4849
]
4950

5051
NOTARY_SCOPES = [
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
# https://developers.docusign.com/docs/admin-api/how-to/create-active-user/
3+
# How to create a new user with active status
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+
# Note: Substitute these values with your own
11+
# Obtain your OAuth token
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+
API_ACCOUNT_ID=$(cat config/API_ACCOUNT_ID)
17+
base_path="https://api-d.docusign.net/management"
18+
ORGANIZATION_ID=$(cat config/ORGANIZATION_ID)
19+
20+
# Construct your API headers
21+
#ds-snippet-start:Admin13Step2
22+
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}"
23+
'--header' "Accept: application/json"
24+
'--header' "Content-Type: application/json")
25+
#ds-snippet-end:Admin13Step2
26+
27+
#ds-snippet-start:Admin13Step3
28+
response=$(mktemp /tmp/response-oa.XXXXXX)
29+
Status=$(curl --request GET ${base_path}/v2/organizations/${ORGANIZATION_ID}/planItems \
30+
"${Headers[@]}" \
31+
--output ${response})
32+
33+
echo "Results from the GET request:"
34+
cat $response
35+
echo ""
36+
37+
PLAN_ID=$(cat $response | sed 's/,/\n/g' | grep plan_id | sed 's/.*\"plan_id\":\"//g' | sed 's/\".*//g')
38+
SUBSCRIPTION_ID=$(cat $response | sed 's/,/\n/g' | grep subscription_id | sed 's/.*\"subscription_id\":\"//g' | sed 's/\".*//g')
39+
#ds-snippet-end:Admin13Step3
40+
41+
request_data=$(mktemp /tmp/request_data-oa.XXXXXX)
42+
43+
read -p "Please enter the account name for the new account: " ACCOUNT_NAME
44+
read -p "Please enter the email address for the new account: " EMAIL_ADDRESS
45+
read -p "Please enter the first name for the new account: " FIRST_NAME
46+
read -p "Please enter the last name for the new account: " LAST_NAME
47+
48+
#ds-snippet-start:Admin13Step4
49+
# The country code value is set to "US" for the developer environment
50+
# In production, set the value to the code for the country of the target account
51+
printf \
52+
'{
53+
"subscriptionDetails": {
54+
"id": "'${SUBSCRIPTION_ID}'",
55+
"planId": "'${PLAN_ID}'",
56+
"modules": []
57+
},
58+
"targetAccount": {
59+
"name": "'${ACCOUNT_NAME}'",
60+
"countryCode": "US",
61+
"admin": {
62+
"email": "'${EMAIL_ADDRESS}'",
63+
"firstName": "'${FIRST_NAME}'",
64+
"lastName": "'${LAST_NAME}'",
65+
"locale": "en"
66+
}
67+
}
68+
}
69+
' >>$request_data
70+
#ds-snippet-end:Admin13Step4
71+
72+
# Create the new account
73+
#ds-snippet-start:Admin13Step5
74+
response=$(mktemp /tmp/response-oa.XXXXXX)
75+
Status=$(curl --request POST ${base_path}/v2/organizations/${ORGANIZATION_ID}/assetGroups/accountCreate \
76+
"${Headers[@]}" \
77+
--data-binary @${request_data} \
78+
--output ${response})
79+
#ds-snippet-end:Admin13Step5
80+
81+
echo "Results from the create account method:"
82+
cat $response
83+
echo ""
84+
85+
# Remove the temporary files
86+
rm "$response"
87+
rm "$request_data"
88+
echo ""
89+
echo "Done."

launcher.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ function startAdmin() {
788788
"Delete_User_Data_Org_Admin" \
789789
"Delete_User_Data_Account_Admin" \
790790
"Clone_Account" \
791+
"Create_Account" \
791792
"Pick_An_API"; do
792793
case "$CHOICE" in
793794

@@ -842,6 +843,10 @@ function startAdmin() {
842843
bash examples/Admin/eg012CloneAccount.sh
843844
startAdmin
844845
;;
846+
Create_Account)
847+
bash examples/Admin/eg013CreateAccount.sh
848+
startAdmin
849+
;;
845850
*)
846851
echo "Default action..."
847852
startAdmin

0 commit comments

Comments
 (0)