Skip to content

Commit 4a7899d

Browse files
author
Balaji Jayaraman
committed
Added Delete and Restore Envelope task
1 parent a5dea73 commit 4a7899d

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Delete and Restore an Envelope
2+
#
3+
# This script performs two sequential operations on a Docusign envelope:
4+
# 1. Deletes the envelope by moving it to the Recycle Bin.
5+
# 2. Pauses for user confirmation.
6+
# 3. Restores the envelope from the Recycle Bin to the Sent Items folder.
7+
#
8+
9+
# Check that we're in a bash shell
10+
if [[ $SHELL != *"bash"* ]]; then
11+
echo "PROBLEM: Run these scripts from within the bash shell."
12+
fi
13+
14+
# Step 1: Obtain your OAuth token
15+
# Note: Substitute these values with your own
16+
ACCESS_TOKEN=$(cat config/ds_access_token.txt)
17+
18+
# Set up variables for full code example
19+
# Note: Substitute these values with your own
20+
account_id=$(cat config/API_ACCOUNT_ID)
21+
22+
base_path="https://demo.docusign.net/restapi"
23+
24+
# Check that we have an envelope id
25+
if [ ! -f config/ENVELOPE_ID ]; then
26+
echo ""
27+
echo "PROBLEM: An envelope id is needed. Fix: execute script eg002SigningViaEmail.sh"
28+
echo ""
29+
exit 0
30+
fi
31+
envelope_id=`cat config/ENVELOPE_ID`
32+
33+
# Get Envelope ID from user or config file
34+
35+
echo ""
36+
echo "Select the envelope ID to use for the delete and restore operations."
37+
echo ""
38+
if [ -f config/ENVELOPE_ID ]; then
39+
envelope_id_from_file=$(cat config/ENVELOPE_ID)
40+
read -p "Use the envelope ID from 'config/ENVELOPE_ID' (${envelope_id_from_file})? (y/n): " use_existing_id
41+
if [[ "$use_existing_id" == "y" || "$use_existing_id" == "Y" ]]; then
42+
envelope_id=$envelope_id_from_file
43+
else
44+
read -p "Please enter the new envelope ID: " new_envelope_id
45+
envelope_id=$new_envelope_id
46+
fi
47+
else
48+
read -p "No envelope ID found. Please enter the envelope ID: " new_envelope_id
49+
envelope_id=$new_envelope_id
50+
fi
51+
52+
if [ -z "$envelope_id" ]; then
53+
echo ""
54+
echo "ERROR: No envelope ID was provided"
55+
echo ""
56+
fi
57+
58+
59+
# PART 1: Delete the Envelope
60+
61+
echo ""
62+
echo "Deleting the Envelope with ID: ${envelope_id}"
63+
echo "Sending PUT request to Docusign..."
64+
echo "Results:"
65+
echo ""
66+
67+
#ds-snippet-start:eSign45Step2
68+
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
69+
--header "Content-Type: application/json" \
70+
--request PUT "${base_path}/v2.1/accounts/${account_id}/folders/recyclebin" \
71+
--data-raw '{
72+
"envelopeIds": [
73+
"'${envelope_id}'"
74+
]
75+
}'
76+
#ds-snippet-end:eSign45Step2
77+
78+
echo ""
79+
echo ""
80+
echo "The deleted envelope is now in your Docusign Recycle Bin."
81+
echo "You can check your web app to confirm the deletion."
82+
83+
84+
# PART 2: Pause for User Confirmation
85+
86+
echo ""
87+
read -p "Press Enter to proceed with restoring the envelope from the Recycle Bin..."
88+
89+
# PART 3: Restore the Envelope
90+
91+
echo ""
92+
echo "Restoring the Envelope from Recycle Bin to the Sent Items folder."
93+
echo "Sending PUT request to Docusign..."
94+
echo "Results:"
95+
echo ""
96+
97+
#ds-snippet-start:eSign45Step3
98+
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
99+
--header "Content-Type: application/json" \
100+
--request PUT "${base_path}/v2.1/accounts/${account_id}/folders/sentitems" \
101+
--data-raw '{
102+
"envelopeIds": [
103+
"'${envelope_id}'"
104+
],
105+
"fromFolderId": "recyclebin"
106+
}'
107+
#ds-snippet-end:eSign45Step3
108+
109+
echo ""
110+
echo ""
111+
echo "The envelope has been restored and is now in your Docusign Sent Items folder."
112+
echo ""

launcher.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ function startSignature() {
313313
"Shared_Access" \
314314
"Document_Generation" \
315315
"Focused_View" \
316+
"Delete_Restore_Envelope" \
316317
"Pick_An_API"; do
317318
case "$CHOICE" in
318319
Pick_An_API)
@@ -486,6 +487,10 @@ function startSignature() {
486487
bash examples/eSignature/eg044FocusedView.sh
487488
startSignature
488489
;;
490+
Delete_Restore_Envelope)
491+
bash examples/eSignature/eg045DeleteRestoreEnvelope.sh
492+
startSignature
493+
;;
489494
*)
490495
echo ""
491496
startSignature
@@ -528,6 +533,7 @@ function startCFRSignature() {
528533
"Bulk_Sending" \
529534
"Scheduled_Sending" \
530535
"Create_Signable_HTML_document" \
536+
"Delete_Restore_Envelope"\
531537
"Pick_An_API"; do
532538
case "$CHOICE" in
533539
Pick_An_API)
@@ -653,6 +659,10 @@ function startCFRSignature() {
653659
bash examples/eSignature/eg038ResponsiveSigning.sh
654660
startCFRSignature
655661
;;
662+
Delete_Restore_Envelope)
663+
bash examples/eSignature/eg045DeleteRestoreEnvelope.sh
664+
startCFRSignature
665+
;;
656666
*)
657667
echo ""
658668
startCFRSignature

0 commit comments

Comments
 (0)