DocumentFlow

Webhooks

Webhooks allow you to receive real-time updates from DocumentFlow when certain events occur. This can be useful for automating your workflow and keeping your systems in sync with DocumentFlow.

Webhook Events

DocumentFlow can send webhook events for various actions. Here are the main events you can subscribe to:

document.processed

Triggered when a document has been successfully processed

document.failed

Triggered when document processing has failed

account.updated

Triggered when your account information is updated

invoice.created

Triggered when a new invoice is generated for your account

Handling Webhooks

When an event occurs, DocumentFlow will send a POST request to your specified webhook URL. Here's how to handle webhook events in different languages:

import express from 'express';
import crypto from 'crypto';

const app = express();
app.use(express.json());

const webhookSecret = 'YOUR_WEBHOOK_SECRET';

app.post('/webhook', (req, res) => {
  const signature = req.headers['x-documentflow-signature'];
  
  // Verify webhook signature
  const hmac = crypto.createHmac('sha256', webhookSecret);
  const digest = hmac.update(JSON.stringify(req.body)).digest('hex');
  
  if (signature !== digest) {
    return res.status(401).json({ error: 'Invalid signature' });
  }

  const event = req.body;
  
  switch (event.type) {
    case 'document.processed':
      // Handle processed document
      console.log('Document processed:', event.data.document_id);
      break;
    case 'document.failed':
      // Handle failed document
      console.log('Document failed:', event.data.document_id);
      break;
  }

  res.json({ received: true });
});

app.listen(3000, () => console.log('Webhook server running'));

Example Webhook Payload

{
  "id": "evt_123456",
  "type": "document.processed",
  "created_at": "2024-01-23T15:51:24Z",
  "data": {
    "document_id": "doc_123456",
    "status": "completed",
    "type": "invoice",
    "results_url": "https://api.documentflow.com/v1/documents/doc_123456"
  }
}

Retry Policy

If your webhook endpoint returns a non-2xx status code or times out, we will retry the webhook using an exponential backoff strategy:

  • First retry: 5 minutes after the initial attempt
  • Second retry: 30 minutes after the first retry
  • Third retry: 2 hours after the second retry
  • Fourth retry: 5 hours after the third retry
  • Fifth retry: 10 hours after the fourth retry

After all retries have been exhausted, we will stop attempting to send the webhook.