Skip to content

Commit a5dea73

Browse files
authored
Merge pull request #125 from docusign/DEVDOCS-17088
adding new web forms code example
2 parents b6ac03b + 646d68d commit a5dea73

File tree

4 files changed

+103
-5
lines changed

4 files changed

+103
-5
lines changed

demo_documents/web-form-config.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Check that we're in a bash shell
2+
if [[ $SHELL != *"bash"* ]]; then
3+
echo "PROBLEM: Run these scripts from within the bash shell."
4+
fi
5+
6+
ds_access_token_path="config/ds_access_token.txt"
7+
8+
# Obtain your OAuth token
9+
# Note: Substitute these values with your own
10+
ACCESS_TOKEN=$(cat ${ds_access_token_path})
11+
12+
# Set up variables for full code example
13+
# Note: Substitute these values with your own
14+
ACCOUNT_ID=$(cat config/API_ACCOUNT_ID)
15+
base_path="https://apps-d.docusign.com/api/webforms/v1.1"
16+
17+
# Create template for the Web Form from the API
18+
bash ./examples/WebForms/lib/createWebFormTemplate.sh
19+
20+
TEMPLATE_ID=$(cat config/WEB_FORM_TEMPLATE_ID)
21+
22+
web_form_config=$(cat demo_documents/web-form-config.json)
23+
result=$(echo "$web_form_config" | sed "s/template-id/$TEMPLATE_ID/g")
24+
echo $result > demo_documents/web-form-config.json
25+
26+
echo ""
27+
echo "Go to your Docusign account to create the Web Form. Go to 'Templates' in your developer account, select 'Start,' select 'Web Forms,' and choose 'Upload Web Form.' Upload the JSON config file 'web-form-config.json' found under the demo_documents folder of this project. You will need to activate the web form before proceeding. Press the enter key after doing so."
28+
read choice
29+
#ds-snippet-start:WebForms2Step2
30+
declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}" \
31+
'--header' "Accept: application/json" \
32+
'--header' "Content-Type: application/json")
33+
#ds-snippet-end:WebForms2Step2
34+
35+
# List web forms in account that match the name of the web form we just created
36+
#ds-snippet-start:WebForms2Step3
37+
response=$(mktemp /tmp/response-cw.XXXXXX)
38+
Status=$(curl -w '%{http_code}' --request GET ${base_path}/accounts/${ACCOUNT_ID}/forms?search=Web%20Form%20Example%20Template \
39+
"${Headers[@]}" \
40+
--output ${response})
41+
42+
FORM_ID=$(cat $response | sed 's/,/\n/g' | grep id | sed 's/.*\"id\":\"//g' | sed 's/\".*//g')
43+
#ds-snippet-end:WebForms2Step3
44+
45+
request_data=$(mktemp /tmp/request-cw-001.XXXXXX)
46+
#ds-snippet-start:WebForms2Step4
47+
printf \
48+
'{
49+
"sendOption": "now",
50+
"formValues": {
51+
"PhoneNumber": "555-555-5555",
52+
"Yes": ["Yes"],
53+
"Company": "Tally",
54+
"JobTitle": "Programmer Writer"
55+
},
56+
"recipients": [
57+
{
58+
"roleName": "signer",
59+
"name": "'"${SIGNER_NAME}"'",
60+
"email": "'"${SIGNER_EMAIL}"'"
61+
}
62+
]
63+
}' >$request_data
64+
#ds-snippet-end:WebForms2Step4
65+
66+
response=$(mktemp /tmp/response-cw.XXXXXX)
67+
#ds-snippet-start:WebForms2Step5
68+
Status=$(curl -w '%{http_code}' -i --request POST ${base_path}/accounts/${ACCOUNT_ID}/forms/${FORM_ID}/instances \
69+
"${Headers[@]}" \
70+
--data-binary @${request_data} \
71+
--output ${response})
72+
#ds-snippet-end:WebForms2Step5
73+
74+
if [[ "$Status" -gt "399" ]] ; then
75+
echo ""
76+
echo "Creating a new instance of the web form..."
77+
echo ""
78+
cat $response
79+
exit 0
80+
fi
81+
82+
echo ""
83+
echo "Response:"
84+
cat $response
85+
echo ""

examples/WebForms/lib/createWebFormTemplate.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ TEMPLATE_ID=`cat $response | grep templateId | sed 's/.*\"templateId\":\"//' | s
3737

3838
echo $TEMPLATE_ID
3939

40-
if [ "${TEMPLATE_ID}" != "" ]; then
40+
if [ -n "${TEMPLATE_ID}" ]; then
4141
echo ""
4242
echo "Your account already includes the '${template_name}' template."
43+
4344
# Save the template id for use by other scripts
45+
if [ ! -f config/TEMPLATE_ID ]; then
46+
echo "Saving the template ID to the config/TEMPLATE_ID file."
47+
fi
4448
echo "${TEMPLATE_ID}" > config/TEMPLATE_ID
49+
4550
rm "$response"
4651
echo ""
4752
echo "Done."
@@ -155,8 +160,12 @@ TEMPLATE_ID=`cat $response | grep templateId | sed 's/.*\"templateId\":\"//' | s
155160

156161
echo ""
157162
echo "Template '${template_name}' was created! Template ID ${TEMPLATE_ID}."
163+
158164
# Save the template id for use by other scripts
159-
echo ${TEMPLATE_ID} > config/WEB_FORM_TEMPLATE_ID
165+
if [ ! -f config/WEB_FORM_TEMPLATE_ID ]; then
166+
echo "Saving the template ID to the config/WEB_FORM_TEMPLATE_ID file."
167+
fi
168+
echo "${TEMPLATE_ID}" > config/WEB_FORM_TEMPLATE_ID
160169

161170
# cleanup
162171
rm "$request_data"
@@ -166,5 +175,4 @@ rm "$doc1_base64"
166175
echo ""
167176
echo ""
168177
echo "Done."
169-
echo ""
170-
178+
echo ""

launcher.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ function startWebForms() {
952952
PS3='Select the action : '
953953
select CHOICE in \
954954
"CreateInstance" \
955+
"CreateRemoteInstance" \
955956
"Home"; do
956957
case "$CHOICE" in
957958

@@ -962,6 +963,10 @@ function startWebForms() {
962963
bash examples/WebForms/eg001CreateInstance.sh
963964
startWebForms
964965
;;
966+
CreateRemoteInstance)
967+
bash examples/WebForms/eg002CreateRemoteInstance.sh
968+
startWebForms
969+
;;
965970
*)
966971
echo "Default action..."
967972
startWebForms

0 commit comments

Comments
 (0)