Webhooks
Webhooks let your systems react when something changes in the CRM, without polling. A change can come from staff in the CRM, from your platform, or from any other connected platform. The CRM sends an HTTPS POST to your URL for every event you subscribe to.
Set up an endpoint#
A CRM administrator adds your URL in Settings → Integrations → Webhooks and picks the events. The CRM then shows a signing secret (whsec_…) once. Store it on your server; you need it to verify deliveries.
Requirements for your URL:
https://on a public address. Private and loopback networks are refused.- Answer with any
2xxstatus within 10 seconds. Do slow work after you answer, from your own queue. - Redirects are not followed.
The admin screen has Send test (a ping event), a delivery log with request bodies and responses, and Retry for failed deliveries.
Events#
| Event | Sent when |
|---|---|
customer.created | A new customer profile is created: staff entry, a push, a pull, a web form or the first order of a new buyer |
customer.updated | Profile details change: name, contact, address, custom fields or original source |
order.created | An order is created by staff, a push or a pull |
order.updated | An order's statuses, total, items or metadata change |
ping | An admin clicks Send test |
Changes to a customer's order totals do not send customer.updated; the matching order.* event covers them. Read data.object.stats when you need the new figures.
The delivery#
POST /webhooks/crm HTTP/1.1
content-type: application/json
user-agent: AbayCRM-Webhooks/1.0
x-webhook-id: evt_4c1f0f6a9d2b7e8a1c3d5f70
x-webhook-event: order.updated
x-webhook-timestamp: 1791282660
x-webhook-signature: sha256=5d2c…
{
"id": "evt_4c1f0f6a9d2b7e8a1c3d5f70",
"type": "order.updated",
"createdAt": "2026-10-06T09:51:00.412Z",
"origin": { "via": "user", "platform": null },
"data": {
"object": {
"object": "order",
"id": "clx…",
"platform": "shopify",
"externalId": "1001",
"deliveryStatus": "delivered",
"…": "the full order object"
}
}
}
data.objectis the full customer or order object as it was when the event happened, the same shape the read API returns.origin.viasays how the change was made:user(staff in the CRM),api(a push),pull(pull sync),form(a web form) orsystem.origin.platformis the platform whose key or pull connection made the change, ornullfor staff and system changes.
Ignore your own changes#
If your platform both pushes orders and subscribes to order.updated, you will receive your own changes back. Skip events where origin.platform is your platform name:
if (event.origin.platform === 'shopify') return res.sendStatus(200);
Verify the signature#
Always check the signature before trusting a delivery. Compute HMAC-SHA256 of x-webhook-timestamp + "." + rawBody with your signing secret, and compare it to the hex value after sha256= in constant time. Also reject timestamps older than a few minutes.
Use the raw request body exactly as received. Re-serialising parsed JSON changes the bytes and the signature will not match.
Node.js (Express)#
import crypto from 'node:crypto';
import express from 'express';
const app = express();
app.post('/webhooks/crm', express.raw({ type: 'application/json' }), (req, res) => {
const ts = req.get('x-webhook-timestamp');
const given = (req.get('x-webhook-signature') || '').replace(/^sha256=/, '');
const expected = crypto.createHmac('sha256', process.env.CRM_WEBHOOK_SECRET).update(`${ts}.`).update(req.body).digest('hex');
const fresh = Math.abs(Date.now() / 1000 - Number(ts)) < 300;
const valid = given.length === expected.length && crypto.timingSafeEqual(Buffer.from(given, 'hex'), Buffer.from(expected, 'hex'));
if (!fresh || !valid) return res.sendStatus(401);
const event = JSON.parse(req.body.toString('utf8'));
res.sendStatus(200); // answer first…
queue.add(event); // …then do the work
});
Python (Flask)#
import hashlib, hmac, os, time
from flask import Flask, abort, request
app = Flask(__name__)
@app.post("/webhooks/crm")
def crm_webhook():
ts = request.headers.get("x-webhook-timestamp", "")
given = request.headers.get("x-webhook-signature", "").removeprefix("sha256=")
expected = hmac.new(os.environ["CRM_WEBHOOK_SECRET"].encode(), f"{ts}.".encode() + request.get_data(), hashlib.sha256).hexdigest()
if abs(time.time() - int(ts or 0)) > 300 or not hmac.compare_digest(given, expected):
abort(401)
event = request.get_json()
enqueue(event)
return "", 200
PHP#
$raw = file_get_contents('php://input');
$ts = $_SERVER['HTTP_X_WEBHOOK_TIMESTAMP'] ?? '';
$given = preg_replace('/^sha256=/', '', $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '');
$expected = hash_hmac('sha256', $ts . '.' . $raw, getenv('CRM_WEBHOOK_SECRET'));
if (abs(time() - (int) $ts) > 300 || !hash_equals($expected, $given)) {
http_response_code(401);
exit;
}
$event = json_decode($raw, true);
http_response_code(200);
Retries and ordering#
A delivery that gets no 2xx answer (an error status, a timeout or a connection failure) is retried after about 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 12 hours. If it still fails it is marked dead, and an admin can resend it from the delivery log. After 20 dead deliveries in a row the endpoint is switched off automatically; turning it back on resets the count.
Because of retries:
- Expect duplicates. Use
id(also inx-webhook-id) to skip events you have already handled. A resent delivery keeps its original id. - Expect events out of order. Compare
data.object.updatedAtwith what you have stored and ignore older versions. When in doubt, fetch the current state from the read API.
Rotating the secret#
Rotate secret in the admin screen issues a new secret straight away; the old one stops working. To rotate without downtime, have your receiver accept either secret for a short while, rotate, deploy the new secret, then remove the old one.