agent: |
xqOFCPY9UZtwsx3XSrBUCheck status of a Docusign envelope
Check status of a Docusign envelope
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
Retrieve the current status (e.g., completed, sent, or voided) of a specific DocuSign envelope.
inputs
outputs
import requests
from requests.exceptions import RequestException
# Configuration
base_url = "https://demo.docusign.net/restapi" # For production, use https://www.docusign.net/restapi
def check_envelope_status():
# API endpoint
url = f"{base_url}/v2.1/accounts/{account_id}/envelopes/{envelope_id}"
# Request headers
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
}
try:
# Send GET request to fetch envelope status
response = requests.get(url, headers=headers)
# Check HTTP response status
if response.status_code == 200:
# Parse and display envelope status
envelope_status = response.json()
print(f"Envelope ID: {envelope_status.get('envelopeId')}")
print(f"Status: {envelope_status.get('status')}")
print(f"Sender: {envelope_status.get('emailSubject')}")
print(f"Created: {envelope_status.get('createdDateTime')}")
print(f"Sent: {envelope_status.get('sentDateTime')}")
print(f"Completed: {envelope_status.get('completedDateTime')}")
elif response.status_code == 401:
print(
"Error: Unauthorized. Please check your access token or account permissions."
)
elif response.status_code == 404:
print("Error: Envelope not found. Ensure the envelope ID is correct.")
elif response.status_code == 400:
print(
f"Error: Bad request. Please check the request payload. Details: {response.text}"
)
elif response.status_code == 403:
print(
"Error: Forbidden. Ensure you have appropriate permissions for this operation."
)
elif response.status_code == 429:
print(
"Error: Too many requests. You are being rate-limited. Try again later."
)
else:
print(f"Unexpected Error: {response.status_code} - {response.text}")
except RequestException as e:
print(f"Network Error: Unable to fetch envelope status. Details: {e}")
except KeyError as e:
print(
f"Error: Missing expected data in the response. Could not retrieve {e}."
)
except Exception as e:
print(f"An unexpected error occurred: {e}")
def main():
try:
if not access_token:
raise ValueError(
"Access Token is missing. Please generate a valid token."
)
if not account_id:
raise ValueError("Account ID is missing. Please provide a valid account ID.")
if not envelope_id:
raise ValueError("Envelope ID is missing. Please provide a valid envelope ID.")
check_envelope_status()
except ValueError as ve:
print(f"Configuration Error: {ve}")
except Exception as e:
print(f"Initialization Error: {e}")
main()
copied