Sign in
agent:
Auto Exec

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