Skip to main content

Webhooks

A destination of kind webhook sends chosen events to a URL of yours as they happen: a new lead, a booking, a handoff, a finished chat.

Setting one up​

Integrations → Destinations → New → Webhook. Give the URL (https:// only), pick the events, and choose whether to include contact details (name, email, phone, company). The console shows the signing secret once (whsec_…); keep it on your server.

Send a test delivers a sample event to your URL right away, and the delivery log shows every attempt with the response you returned.

The request​

POST /your/path HTTP/1.1
Content-Type: application/json
X-Sarthi-Event: gate.captured
X-Sarthi-Event-Version: 1
X-Sarthi-Delivery: 01a11fa5-cf24-70f7-8856-fea44a434f75
X-Sarthi-Timestamp: 1791532322
X-Sarthi-Signature: sha256=4911d0c96ee361f9d881d12b6c25dc239e6a2f77622a61449d85e34e05b8ed6d
X-Saarthi-Event: gate.captured
X-Saarthi-Event-Version: 1
X-Saarthi-Delivery: 01a11fa5-cf24-70f7-8856-fea44a434f75
X-Saarthi-Timestamp: 1791532322
X-Saarthi-Signature: sha256=4911d0c96ee361f9d881d12b6c25dc239e6a2f77622a61449d85e34e05b8ed6d

Every header comes twice: as X-Sarthi-*, and with the same value as X-Saarthi-*, its name before the brand's spelling was fixed. Receivers written for the older names keep working; new code reads X-Sarthi-*.

{
"id": "01a11fa5-cf24-70f7-8856-fea44a434f75",
"type": "gate.captured",
"version": 1,
"occurredAt": "2026-10-09T07:52:02.596Z",
"workspaceId": "01a11fa5-c7da-722a-b339-039a85acdd9e",
"data": {
"conversationId": "01a11fa5-cc7f-71d0-acaa-a0816fc264a3",
"leadId": "01a11fa5-cc80-7c2b-9d4e-1b5c0a2e9f10",
"pageUrl": "https://acme.in/pricing",
"name": "Ravi Mehta",
"email": "ravi@mehta.in",
"phone": "+919810012345"
}
}

data holds the fields listed for the event on the events reference; contact fields are present only if the destination includes them.

Verifying the signature​

The signature is sha256= + HMAC-SHA256 of <timestamp>.<raw body> with your signing secret. Verify it on the raw bytes, before parsing the JSON, and reject timestamps older than a few minutes.

With the SDK (npm install @mysarthi/sdk), one call checks the signature and the age:

import express from 'express';
import { verifyWebhook } from '@mysarthi/sdk';

// Express: keep the raw body.
app.post('/saarthi', express.raw({ type: 'application/json' }), (req, res) => {
if (!verifyWebhook(req.body, req.headers, process.env.SARTHI_WEBHOOK_SECRET)) {
return res.status(401).end();
}
const event = JSON.parse(req.body);
// … handle it, quickly; do the slow work after responding
res.status(204).end();
});

In a Next.js route handler, pass await request.text() and request.headers. Without the SDK:

import { createHmac, timingSafeEqual } from 'node:crypto';

// rawBody: the request body exactly as received (a string), before JSON.parse.
export const isFromSarthi = (headers, rawBody, secret) => {
const timestamp = headers['x-sarthi-timestamp'];
const signatures = headers['x-sarthi-signature'];
if (!timestamp || !signatures) return false; // not from Sarthi
// Older than 5 minutes, or not a number: refused.
if (!(Math.abs(Date.now() / 1000 - Number(timestamp)) <= 300)) return false;
const expected = Buffer.from(
`sha256=${createHmac('sha256', secret).update(`${timestamp}.${rawBody}`).digest('hex')}`,
);
// During a rotation the header holds two signatures: "sha256=<new>, sha256=<old>".
return signatures.split(',').some((s) => {
const given = Buffer.from(s.trim());
return given.length === expected.length && timingSafeEqual(given, expected);
});
};

Responding, retries and duplicates​

  • Answer 2xx within a few seconds. Do slow work (CRM calls, emails) after responding, from a queue.
  • Anything else is retried: after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours (6 tries in all). Answer 410 Gone to make Sarthi pause the destination.
  • Delivery is at least once and the order isn't guaranteed. Use id (also in X-Saarthi-Delivery) to drop an event you have already handled.
  • After 20 failed deliveries in a row the destination is marked failing and you are told; it pauses itself if that goes on. Resume it from the console once your endpoint is back.

Rotating the secret​

Rotate in the destination's page. For 24 hours every delivery carries two signatures (new and old, comma-separated), so you can switch your server without missing an event. The verification code above handles both.

Other destinations​

Slack, HubSpot and an email inbox take the same events without any code: see Integrations.