Skip to content
Select theme
Light
Dark
Auto
Select language
English
فارسی

Webhooks

When something happens in a shop, Kaladan sends each app that subscribed an HTTPS POST, signed with the app’s signing secret.

Topics are declared on an app version, each with its endpoint. Installing the version creates the subscriptions; there is no call to subscribe at runtime.

webhookSubscriptions: [
{ topic: "orders/paid", endpoint: "https://anbar.example.ir/hooks" }
{ topic: "products/update", endpoint: "https://anbar.example.ir/hooks", includeFields: ["id", "title", "status"] }
]

A topic needs its scope among the version’s requestedScopes.

TopicScopeWhen
orders/createREAD_ORDERSAn order was placed. Not necessarily paid.
orders/updatedREAD_ORDERSAn order changed after it was placed.
orders/paidREAD_ORDERSPayment was verified with the gateway: the one event that means money arrived.
orders/cancelledREAD_ORDERSAn order was cancelled, with the reason.
refunds/createREAD_PAYMENTSMoney was given back.
transactions/unresolvedREAD_PAYMENTSA payment could not be verified, and reconciliation took it over.
fulfillments/createREAD_FULFILLMENTSA parcel was handed to a carrier.
products/createREAD_PRODUCTSA product was created.
products/updateREAD_PRODUCTSA product changed; changed names which fields.
products/deleteREAD_PRODUCTSA product was deleted. Carries only its id.
inventory_levels/updateREAD_INVENTORYStock moved at a location. High volume: subscribe narrowly.
customers/createREAD_CUSTOMERSA customer record was created.
customers/updateREAD_CUSTOMERSA customer record changed.
job/completed—A long-running job finished. Subscribe instead of polling.
app/uninstalled—The merchant removed your app. Its tokens are already revoked.
TopicWhat to do
customers/data_requestA buyer asked for what your app holds about them. Return it to the merchant within 30 days.
customers/redactErase that buyer’s personal data.
shop/redactErase everything you hold for the shop. Sent 48 hours after an uninstall, and withdrawn if the merchant reinstalls within that window.
POST https://anbar.example.ir/hooks
Content-Type: application/json
webhook-id: evt_01JQ8Z3MK4TRXG7
webhook-timestamp: 1789000000
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=
X-Kaladan-Topic: orders/paid
X-Kaladan-Shop: Z2lkOi8va2FsYWRhbi9TaG9wL…
X-Kaladan-Sequence: 4417
X-Kaladan-Delivery-Id: dlv_01JQ8Z3N2P
X-Kaladan-Attempt: 1
X-Kaladan-Api-Version: 2026-10

The body is an envelope, described by a JSON Schema:

{
"eventId": "evt_01JQ8Z3MK4TRXG7",
"topic": "orders/paid",
"apiVersion": "2026-10",
"occurredAt": "2026-11-09T08:12:44Z",
"sequence": 4417,
"shop": { "id": "…", "handle": "golnar", "primaryDomain": "golnar.ir" },
"actor": { "kind": "CUSTOMER" },
"payload": { "…": "the order, cut to your app's scopes" },
"test": false
}

Payloads are cut to the scopes the merchant granted: a field your app may not read is absent.

Kaladan signs with Standard Webhooks, so any of its libraries verifies a delivery with no Kaladan-specific code. By hand:

key = base64_decode(signing secret without its "whsec_" prefix)
signed = webhook-id + "." + webhook-timestamp + "." + raw body
expected = "v1," + base64(hmac_sha256(key, signed))
import { createHmac, timingSafeEqual } from 'node:crypto';
export function verify(rawBody, headers, secret) {
const id = headers['webhook-id'];
const timestamp = headers['webhook-timestamp'];
// Older than five minutes, or from the future: a replay.
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
const expected = Buffer.from(
'v1,' + createHmac('sha256', key).update(`${id}.${timestamp}.${rawBody}`).digest('base64'),
);
// One entry, or two while a secret is being rotated.
return headers['webhook-signature'].split(' ').some((entry) => {
const candidate = Buffer.from(entry);
return candidate.length === expected.length && timingSafeEqual(candidate, expected);
});
}
  • Verify the raw bytes, before parsing. Re-serialized JSON is different bytes.
  • Compare in constant time. A plain == leaks your secret one byte at a time.
  • Reject a timestamp more than five minutes away, and anything unverified with 401.
  • During a rotation the header carries two signatures, the new secret’s first, for one day.
  • Answer 2xx within five seconds. Acknowledge first, then do the work: an endpoint that processes before it answers gets retried while it is still working.
  • 410 Gone turns the subscription off for good. It is the honest way to retire an endpoint.
  • Anything else, a timeout, or a TLS failure is retried.

Each delivery is retried with backoff over about two days:

1m → 5m → 15m → 45m → 2h → 5h → 12h → 24h

After the last attempt it waits in a dead-letter queue for seven days, where you can inspect it and replay it with webhookDeliveryReplay. If every delivery to an endpoint fails for 24 hours, the subscription is switched off; webhookSubscriptionReenable turns it back on and replays what is still queued.

  • The same event can arrive twice. Deduplicate on webhook-id, and keep the ids for at least 48 hours.
  • Events can arrive out of order. Retries are per delivery, so a failure does not hold back later events. Order by X-Kaladan-Sequence, which rises per shop and per resource.
  • Quote X-Kaladan-Delivery-Id when you ask for help with a delivery.