How to Automate E-Signature Collection for Contracts
Send contracts for signature and track completion automatically.
Jay Banlasan
The AI Systems Guy
This system automates esignature contract collection by triggering signature requests when deals reach the contract stage. No manual uploads, no forgotten follow-ups.
What You Need Before Starting
- Python 3.8+
- Claude or GPT API key
- Jinja2 for templating
- weasyprint for PDF generation
Step 1: Connect E-Signature API
DocuSign, PandaDoc, and HelloSign all have APIs. Pick the one your clients already trust. Build a simple wrapper so you can swap providers without rewriting your automation.
import requests
import json
class ESignClient:
def __init__(self, api_key, base_url):
self.headers = {"Authorization": f"Bearer {api_key}"}
self.base_url = base_url
def create_envelope(self, doc_path, signers):
with open(doc_path, "rb") as f:
return requests.post(
f"{self.base_url}/envelopes",
headers=self.headers,
files={"doc": f},
data={"signers": json.dumps(signers)}
).json()
def send_reminder(self, envelope_id):
return requests.post(
f"{self.base_url}/envelopes/{envelope_id}/remind",
headers=self.headers
).json()
Step 2: Auto-Trigger on Stage Change
When a deal reaches the contract stage in your CRM, the system generates the contract and sends it for signature without anyone lifting a finger. Listen for CRM webhooks to catch the stage change in real time.
def on_stage_change(deal_id, new_stage):
if new_stage == "contract_sent":
deal = crm_client.get_deal(deal_id)
contract_path = generate_contract(deal)
envelope = esign_client.create_envelope(
contract_path,
[{"email": deal["contact_email"], "name": deal["contact_name"]}]
)
crm_client.update_deal(deal_id, {"envelope_id": envelope["id"]})
log_action(deal_id, "contract_sent", envelope["id"])
Step 3: Track Status via Webhooks
Set up a webhook endpoint to receive signature events. When the contract is signed, update the CRM automatically. When it is declined, alert the rep immediately so they can address the issue.
from flask import Flask, request
app = Flask(__name__)
@app.route("/webhook/esign", methods=["POST"])
def esign_webhook():
event = request.json
deal_id = get_deal_by_envelope(event["envelope_id"])
if event["type"] == "completed":
crm_client.update_deal(deal_id, {"stage": "closed_won"})
send_notification(f"Contract signed for deal {deal_id}")
elif event["type"] == "declined":
alert_rep(deal_id, "Contract was declined by the prospect")
return {"status": "ok"}
Step 4: Send Automated Reminders
If the contract sits unsigned for 48 hours, send a gentle nudge. Cap it at 3 reminders. After that, escalate to the sales manager for a phone call.
from datetime import datetime
def check_unsigned_contracts(older_than_hours=48):
pending = get_pending_envelopes(older_than_hours)
for env in pending:
reminder_count = get_reminder_count(env["id"])
if reminder_count < 3:
esign_client.send_reminder(env["id"])
log_reminder(env["id"])
elif reminder_count == 3:
escalate_to_manager(env["deal_id"],
reason="Contract unsigned after 3 reminders")
Step 5: Archive Signed Contracts
Once signed, download the completed document, save it to your file system, and attach it to the CRM record. This creates a clean paper trail without manual file management.
def archive_signed_contract(envelope_id):
doc = esign_client.download_completed(envelope_id)
deal_id = get_deal_by_envelope(envelope_id)
path = f"contracts/signed/{deal_id}_{datetime.now().strftime('%Y%m%d')}.pdf"
with open(path, "wb") as f:
f.write(doc)
crm_client.attach_file(deal_id, path)
log_action(deal_id, "contract_archived", path)
What to Build Next
Add automatic reminders for unsigned contracts. Escalate after 3 days.
Related Reading
- Setting Up Automated Data Collection - automated data collection setup
- Setting Up Automated Contract Management - automated contract management setup
- Setting Up Automated Social Proof Collection - automated social proof collection
Want this system built for your business?
Get a free assessment. We will map every system your business needs and show you the ROI.
Get Your Free Assessment