Developer
Build a signing workflow with webhooks: from sent to stored
A reliable signing workflow does four things: it creates an envelope tagged with your own record ID, verifies each webhook, updates your record, and stores the signed PDF when envelope-completed arrives. Build it to tolerate duplicate, late and out-of-order events, and it will keep working through outages.
Map events to actions
Decide what your system does at each event. Subscribe only to those you use. These are all 11 event names:
- envelope-sent and recipient-sent: mark the record as out for signature.
- recipient-delivered: the recipient opened the link.
- recipient-completed: one recipient finished.
- envelope-completed: everyone finished, so download and store the files.
- recipient-declined and envelope-declined: stop and alert the record's owner.
- envelope-voided and envelope-expired: close the record, or queue a new send.
- recipient-corrected and recipient-reassigned: update the contact on your record.
Tag the envelope and register your endpoint
When you create the envelope, add your own ID: "metadata": {"orderId": "4411"}. Then register one https URL on a public address. Each account has one webhook. The secret is returned only when the webhook is first created, so store it then. It is also shown on the Developer page, where you can replace it.
curl -X PUT https://docaisign.com/api/v1/webhook \
-H "Authorization: Bearer $DOCAISIGN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/hooks/docaisign",
"events": ["recipient-declined", "envelope-completed",
"envelope-declined", "envelope-voided", "envelope-expired"]
}' Verify, save and acknowledge
Each request carries X-DocAISign-Event, X-DocAISign-Delivery and X-DocAISign-Signature. The signature is sha256= followed by the hex HMAC-SHA256 of the raw body, keyed with your secret. Compute it before parsing, because re-serialised JSON will not match. This Node.js handler uses Express:
app.post('/hooks/docaisign', express.raw({ type: 'application/json' }), async (req, res) => {
const expected = Buffer.from('sha256=' +
crypto.createHmac('sha256', SECRET).update(req.body).digest('hex'));
const received = Buffer.from(req.get('X-DocAISign-Signature') ?? '');
if (expected.length !== received.length ||
!crypto.timingSafeEqual(expected, received)) return res.sendStatus(401);
const deliveryId = req.get('X-DocAISign-Delivery');
const event = JSON.parse(req.body.toString('utf8'));
// Insert once (unique deliveryId), then process in a background job.
await saveEventOnce(deliveryId, event);
res.sendStatus(200);
}); Read the payload
Every event has event, id, at and envelope. Recipient events also include recipient, and some envelope events list recipients. The envelope includes your metadata, signedSha256 and testMode. This example is shortened:
{
"event": "envelope-completed",
"id": "EVENT_ID",
"at": "2026-11-18T15:04:05.0000000Z",
"envelope": {
"id": "ENVELOPE_ID",
"status": "completed",
"signedSha256": "9f2c...",
"testMode": false,
"metadata": { "orderId": "4411" }
},
"recipient": null,
"recipients": [ { "slot": 1, "email": "[email protected]", "status": "completed" } ]
} Plan for retries, duplicates and order
Any response other than 2xx counts as a failure, and so do a network error, a redirect and a response slower than 5 seconds. DocAISign then retries after 1 minute, 5 minutes, 30 minutes, 2 hours and 8 hours. That is six attempts over about 11 hours.
- Duplicates: the delivery ID stays the same across retries, so ignore one you have already saved.
- Order: a retried event can arrive after a newer one, so never move a finished record backwards.
- Current state: when in doubt, call GET /api/v1/envelopes/{id}.
- Outages: after the last attempt the event is marked Gave up under Recent deliveries. Run a daily check with GET /api/v1/envelopes?status=completed to catch anything you missed.
- Unknown events: return 200 for names you do not handle, including the test event.
Store the signed files
In your background job, download the signed PDF and the certificate. Compare the SHA-256 of the signed PDF with envelope.signedSha256 before you mark the record as stored. Use the signed kind for this check, because the combined file is a different file with its own fingerprint.
Retry the job if storage fails. Signed files are currently deleted from DocAISign 30 days after signing, and the download then returns 404. Each download is also recorded in the envelope's audit trail.
BASE=https://docaisign.com/api/v1/envelopes/ENVELOPE_ID/documents
AUTH="Authorization: Bearer $DOCAISIGN_API_KEY"
curl -H "$AUTH" -o signed.pdf "$BASE/signed"
curl -H "$AUTH" -o certificate.pdf "$BASE/certificate"
sha256sum signed.pdf # must equal envelope.signedSha256
Handle the unhappy paths
A declined or expired envelope returns to draft in DocAISign, and its files are deleted after 7 days unless it is sent again. A voided envelope's files are also deleted after 7 days. Show the decline reason from recipient.declineReason to the record's owner, and let a person decide whether to correct the document and send it again.
Test the whole flow
Use Send test event on the Developer page to check your endpoint and signature code. It posts an event named test. Then run a real flow with a test key: test envelopes fire the same events, and envelope.testMode is true, so keep those files out of production storage. Try a decline, a void and a failed response from your server as well as the normal path.
Common questions
Can I have a different webhook URL for each template?
No. Each account has one webhook URL, so route events in your own handler, for example by a value in metadata.
Can I use a localhost address during development?
No. Production webhooks need a public https address, so use a public tunnel or a staging server.
Should I trust browser events from embedded signing?
Use them only to update the page. Confirm the result on your server with a verified webhook.