Skip to main content

Webhooks

Receive real-time notifications about events in ZenSearch.

Overview

Webhooks allow you to:

  • Get notified when syncs complete
  • Track document processing
  • Monitor connector status
  • Build integrations

Creating Webhooks

Endpoint

POST /v1/webhooks

Request Body

{
"url": "https://your-server.com/webhook",
"events": ["sync.completed", "document.indexed"],
"secret": "your-webhook-secret"
}

Parameters

ParameterTypeRequiredDescription
urlstringYesEndpoint URL
eventsstring[]YesEvents to subscribe
secretstringNoSigning secret

Event Types

EventDescription
sync.startedSync job started
sync.completedSync job completed
sync.failedSync job failed
document.indexedDocument indexed
document.deletedDocument deleted
connector.createdConnector created
connector.deletedConnector deleted

Webhook Payload

Headers

X-Webhook-ID: wh_abc123
X-Webhook-Signature: sha256=...
X-Webhook-Timestamp: 1705766400
Content-Type: application/json

Body

{
"id": "evt_abc123",
"type": "sync.completed",
"timestamp": "2024-01-20T14:00:00Z",
"data": {
"connectorId": "conn_xyz",
"jobId": "job_123",
"documentsProcessed": 150,
"duration": 45000
}
}

Verifying Signatures

Verify webhook authenticity using the signature:

Node.js

const crypto = require('crypto');

function verifySignature(payload, signature, secret) {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return `sha256=${expected}` === signature;
}

Python

import hmac
import hashlib

def verify_signature(payload, signature, secret):
expected = hmac.new(
secret.encode(),
payload.encode(),
hashlib.sha256
).hexdigest()
return f"sha256={expected}" == signature

Managing Webhooks

List Webhooks

GET /v1/webhooks

Update Webhook

PUT /v1/webhooks/{id}

Delete Webhook

DELETE /v1/webhooks/{id}

Test Webhook

POST /v1/webhooks/{id}/test

Retry Policy

Failed deliveries are retried:

AttemptDelay
1Immediate
21 minute
35 minutes
430 minutes
52 hours

After 5 failures, the webhook is disabled.

Best Practices

  1. Respond quickly: Return 2xx within 5 seconds
  2. Process async: Queue events for processing
  3. Verify signatures: Always validate authenticity
  4. Handle duplicates: Events may be delivered multiple times
  5. Monitor failures: Set up alerting for webhook failures

Next Steps