Skip to main content
Webhooks provide real-time notifications when flow executions complete, eliminating the need for polling. This guide covers building secure, production-ready webhook handlers.

Prerequisites

  • Node.js 18+
  • A web framework (Next.js, Express, Fastify, etc.)
  • A publicly accessible URL (or ngrok for local development)
  • Your webhook signing secret from the Doclo dashboard

How Webhooks Work

  1. Your app starts an async execution with a webhookUrl
  2. Doclo processes the document
  3. When complete, Doclo sends an HTTP POST to your webhook URL
  4. Your handler verifies the signature and processes the result

Webhook Payload

Doclo sends a JSON payload with this structure:

Signature Verification

Every webhook includes a signature header for authentication. Always verify signatures in production.

Header Format

The signature is an HMAC-SHA256 hash of the raw request body using your webhook secret.

SDK Verification

The easiest way to verify signatures:

Manual Verification

If you need to verify without the SDK:
Always use timingSafeEqual for signature comparison. Regular string comparison is vulnerable to timing attacks.

Next.js Handler

Express Handler

Fastify Handler

Database Integration

Save extraction results to your database:

Idempotent Processing

Webhooks may be delivered multiple times. Ensure your handler is idempotent:

Retry Behavior

Doclo retries failed webhook deliveries automatically: A delivery is considered failed if:
  • Your server returns a non-2xx status code
  • Connection times out (30 seconds)
  • Connection cannot be established
Return a 200 response quickly, even if you’re still processing. Queue the work for async processing if it takes time.

Async Processing Pattern

For complex processing, acknowledge immediately and process async:
Then process with a worker:

Local Development

Use ngrok to expose your local server:
Use the ngrok URL as your webhook URL:

Security Best Practices

  1. Always verify signatures - Never process unverified webhooks
  2. Use HTTPS - Ensure your endpoint uses TLS
  3. Validate timestamps - Reject old webhooks to prevent replay attacks
  4. Store secrets securely - Use environment variables, never commit secrets
  5. Log cautiously - Don’t log sensitive data from webhook payloads
  6. Rate limit - Protect against abuse even with signature verification

Monitoring and Alerting

Track webhook health:
Set up alerts for:
  • High webhook failure rates
  • Long processing times
  • Missing webhooks (executions completing without webhook delivery)
  • Signature verification failures (possible security issues)

Get Your Webhook Secret

  1. Log in to app.doclo.ai
  2. Navigate to Settings > Webhooks
  3. Copy your webhook signing secret
  4. Store it as DOCLO_WEBHOOK_SECRET in your environment

Next Steps

Webhooks

Webhook configuration reference

Next.js Integration

Complete Next.js example

Error Recovery

Handle failures gracefully

Polling Results

Alternative to webhooks