Sign in
agent:

Docusign Integration Tasks

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
  1. 1

    Creating a Docusign app for provisioning api credentials

    There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
    1. Go to Docusign Admin Console
    2. Go to Integrations >>> Apps and Keys
    3. Click on Add App and Integration Key
    4. Give App Name, Create Secret Key, Create an RSA key pair for authentication or upload your own public key.
    5. Give a redirect URI for one time consent to generate access tokens for authentication. App creation is finished here.
    6. Note the Integration key, user ID, Private key contents and auth server (auth_server = "account-d.docusign.com") [for demo accounts] to be used for creating an access token.
    7. After generating the token, Use Account Base URI, API Account ID and account token to do tasks programmatically.
    1
  2. 2

    Generate Access Token for Docusign Integration App

    There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

    Create a JWT-based access token to authenticate and interact with the DocuSign API.

    import requests import time import jwt # Configuration # To be received from the Input Parameters # integration_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" #docusign application key # user_id = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # API User ID from DocuSign auth_server = "account-d.docusign.com" # Use "account-d.docusign.com" for demo developer accounts # private_key = """-----BEGIN RSA PRIVATE KEY----- # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX # -----END RSA PRIVATE KEY-----""" # Create JWT token current_time = int(time.time()) payload = { "iss": integration_key, "sub": user_id, "aud": auth_server, "iat": current_time, # Issued at time "exp": current_time + 3600, # Token expiration (1 hour) "scope": "signature impersonation" } jwt_token = jwt.encode(payload, private_key, algorithm="RS256") # Request access token url = f"https://{auth_server}/oauth/token" headers = {"Content-Type": "application/x-www-form-urlencoded"} body = { "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer", "assertion": jwt_token } response = requests.post(url, headers=headers, data=body) # Handle the response if response.status_code == 200: access_token = response.json()["access_token"] print("Access Token:", access_token) else: print("Error:", response.json())
    copied
    2
  3. 3

    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.

    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
    3
  4. 4

    List All Docusign Templates

    There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

    Fetch and display a list of all templates available in the specified DocuSign account.

    import requests # Configuration base_url = "https://demo.docusign.net/restapi" # For production, use https://www.docusign.net/restapi # Endpoint to list templates url = f"{base_url}/v2.1/accounts/{account_id}/templates" # Headers with the access token headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } # Make the API call response = requests.get(url, headers=headers) # Handle the response if response.status_code == 200: templates = response.json() envelope_templates = templates.get("envelopeTemplates", []) if envelope_templates: print("Templates List:") for template in envelope_templates: print(f"ID: {template['templateId']}, Name: {template['name']}") else: print("No templates found in the account.") else: print("Error:", response.json())
    copied
    4
  5. 5

    List All Docusign Envelopes/Documents for the past 7 days

    There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

    Retrieve and display a list of envelopes/documents created in the last 7 days.

    import requests from datetime import datetime, timedelta # Configuration base_url = "https://demo.docusign.net/restapi" # For production, use https://www.docusign.net/restapi # List documents in your account for the past 7 days def list_documents(): # Calculate the start date (7 days ago) and end date (current date) seven_days_ago = (datetime.now() - timedelta(days=7)).strftime("%Y-%m-%dT%H:%M:%SZ") today = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") url = f"{base_url}/v2.1/accounts/{account_id}/envelopes" headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json", } params = { "status": "completed", # Retrieve only completed envelopes "from_date": seven_days_ago, # Start date (7 days ago) "to_date": today, # End date (current date) } response = requests.get(url, headers=headers, params=params) if response.status_code == 200: envelopes = response.json().get("envelopes", []) if envelopes: print("List of envelopes/documents in your account for the past 7 days:") for envelope in envelopes: print(f"Envelope ID: {envelope['envelopeId']}") print(f"Document Name: {envelope.get('emailSubject', 'N/A')}") print(f"Status: {envelope['status']}") print(f"Created Date: {envelope['createdDateTime']}") print("-" * 30) else: print("No envelopes/documents found for the past 7 days.") else: print(f"Error retrieving documents: {response.status_code} - {response.text}") # Call the function to list documents list_documents()
    copied
    5
  6. 6

    Fetch a Docusign template by ID

    There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

    Retrieve details of a specific DocuSign template using its unique template ID.

    import requests # Configuration base_url = "https://demo.docusign.net/restapi" # For production, use https://www.docusign.net/restapi # Endpoint to fetch a template url = f"{base_url}/v2.1/accounts/{account_id}/templates/{template_id}" # Headers with the access token headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } # Make the API call response = requests.get(url, headers=headers) # Handle the response if response.status_code == 200: template = response.json() print("Template Details:") print(f"Name: {template['name']}") print(f"ID: {template['templateId']}") print(f"Description: {template.get('description', 'No description')}") print(f"Shared: {template.get('shared', 'No info')}") elif response.status_code == 404: print(f"Template with ID '{template_id}' not found. Please check the template ID and try again.") else: print("An error occurred while fetching the template:") print(f"Status Code: {response.status_code}") print("Response:", response.json())
    copied
    6
  7. 7

    Send a Docusign Envelope for signing to a recipient using a template

    There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

    Send a document for electronic signature by utilizing a predefined template and recipient details.

    import requests from requests.exceptions import RequestException # Configuration base_url = "https://demo.docusign.net/restapi" # For production, use https://www.docusign.net/restapi def send_envelope_from_template(): # API endpoint url = f"{base_url}/v2.1/accounts/{account_id}/envelopes" # Request headers headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json", } # Envelope definition body = { "templateId": template_id, "status": "sent", # "created" to save as draft, "sent" to send immediately "templateRoles": [ { "roleName": "signer", # Role name defined in the template "name": recipient_name, "email": recipient_email, "routingOrder": "1", } ], "emailSubject": "Please sign the Consulting Contract", "emailBlurb": "Hi, Please review and sign the consulting contract template.", } try: # Send the envelope response = requests.post(url, headers=headers, json=body) # Check for HTTP response status if response.status_code == 201: envelope_id = response.json().get("envelopeId") print(f"Envelope sent successfully! Envelope ID: {envelope_id}") elif response.status_code == 401: print( "Error: Unauthorized. Please check your access token or account permissions." ) elif response.status_code == 404: print( "Error: Resource not found. Ensure your account ID, template ID, or URL 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 send the envelope. Details: {e}") except KeyError: print( "Error: Unexpected response format. Could not retrieve envelope ID. Please verify your API response." ) 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 template_id: raise ValueError("Template ID is missing. Please provide a valid template ID.") send_envelope_from_template() except ValueError as ve: print(f"Configuration Error: {ve}") except Exception as e: print(f"Initialization Error: {e}") main()
    copied
    7