Webhooks
Webhooks notify your server of email and contact events within seconds.
Create endpoints with the routes below, or in Settings › Webhooks (admins and owners), where you can also send a test event, see each delivery and retry it.
Account endpoints
An account endpoint receives the events of every space of the account: one URL and one secret, however many spaces you run. Each event tells its space in space_id.
- Mode. An account endpoint is live or test. A live one receives the events of live spaces, a test one those of test spaces.
- Same behavior. Event types, payload, signature, retries and the 50-failure rule are those of space endpoints.
- Both. An event reaches the endpoints of its space and the account endpoints, each with the same event
id. - Deleting a space keeps the account endpoints. Their deliveries for that space are deleted.
Manage them in Account › Account webhooks (admins and owners), or with an account key on /v1/account/webhooks.
Event types
| Type | Sent when |
|---|---|
email.sent | Kula sent the email; delivery to the inbox comes next |
email.delivered | The receiving server accepted the email |
email.bounced | The email bounced. bounce_type tells whether it is permanent. Bounces explained |
email.complained | The recipient marked the email as spam |
email.opened | First open by a person (privacy proxies and scanners are ignored) |
email.clicked | First click by a person, with the url |
contact.subscribed | A contact joined a list (sign-up form, confirmed double opt-in, API, dashboard). Imports don't send it |
contact.unsubscribed | A contact left a list, or every list |
campaign.failed | A scheduled campaign could not leave: quota reached, sender no longer verified, link flagged as dangerous |
campaign.expired | Marketing stayed paused for 24 hours while a campaign was sending: its emails not sent yet were cancelled |
space.confirmations_held | Double opt-in signups are paused: too many confirmations went unconfirmed |
space.confirmations_resumed | The pause ended: double opt-in signups are taken again |
Email events cover every email of the space: transactional, campaigns and flows.
Payload
Every event has the same envelope:
{
"id": "evt_5f0c7d2b9a8e4f1c8b3a6d9e2f1c0b7a",
"type": "email.bounced",
"created_at": "2026-10-17T09:30:04Z",
"space_id": "3f1c9a52-7b0e-4d8a-9c61-2e5f8b7a4d10",
"livemode": true,
"data": { ... }
}
livemode is false for an event of a test space.
Email events
{
"id": "evt_5f0c7d2b9a8e4f1c8b3a6d9e2f1c0b7a",
"type": "email.bounced",
"created_at": "2026-10-17T09:30:04Z",
"space_id": "3f1c9a52-7b0e-4d8a-9c61-2e5f8b7a4d10",
"livemode": true,
"data": {
"message_id": "8f6c2a1e-3b4d-4e5f-9a0b-1c2d3e4f5a6b",
"to": "ada@example.com",
"subject": "Reset your password",
"template_id": "c41d7e2a-9b8f-4a6e-b3d2-5f1e0a9c8b7d",
"tags": { "user_id": "usr_1042" },
"bounce_type": "HARD",
"detail": "550 5.1.1 The email account that you tried to reach does not exist"
}
}
| Field | Present |
|---|---|
message_id | Always: the id returned by POST /v1/emails |
to, subject | Always |
campaign_id, flow_id, template_id | When the email came from a campaign, a flow or a template |
tags | Always: the tags you set when sending (empty object otherwise) |
bounce_type | email.bounced: HARD (the address does not exist), SOFT (temporary, such as a full inbox) or BLOCKED (refused by the receiving server) |
detail | email.bounced: the server's answer |
url | email.clicked: the link clicked |
Contact events
{
"id": "evt_9a1b2c3d4e5f60718293a4b5c6d7e8f9",
"type": "contact.unsubscribed",
"created_at": "2026-10-17T11:02:00Z",
"space_id": "3f1c9a52-7b0e-4d8a-9c61-2e5f8b7a4d10",
"livemode": true,
"data": {
"contact_id": "0d9e8f7a-6b5c-4d3e-2f1a-0b9c8d7e6f5a",
"email": "ada@example.com",
"list_id": "5a8e2c1f-0b3d-4e6a-9f7c-2d1e8b4a6c3f",
"reason": "USER"
}
}
| Field | Values |
|---|---|
list_id | The list joined or left. null on contact.unsubscribed when the contact left every list |
source | contact.subscribed: FORM, API, DASHBOARD or MCP |
form_id | contact.subscribed: the form or landing page of the subscription, when it comes from one |
reason | contact.unsubscribed: USER (unsubscribe link, one-click button or preferences page), API, DASHBOARD, INACTIVE (unsubscribed from the dashboard after 6 months without opens or clicks), BOUNCE or COMPLAINT |
Campaign events
{
"id": "evt_1f2e3d4c5b6a79880716253443526170",
"type": "campaign.failed",
"created_at": "2026-10-19T08:00:03Z",
"space_id": "3f1c9a52-7b0e-4d8a-9c61-2e5f8b7a4d10",
"livemode": true,
"data": {
"campaign_id": "7c2d9e4f-1a3b-4c5d-8e6f-9a0b1c2d3e4f",
"name": "October newsletter",
"reason": "Google flags a link of this email as dangerous: https://example.net/promo. Remove it and schedule the campaign again."
}
}
campaign.expired carries campaign_id, name, expired (how many emails were cancelled) and reason.
space.confirmations_held carries held_until (end of the pause), hold_count (pauses in a row: 1 for 6 hours, then 12, 24 and 48), sent and confirmed (confirmations behind the decision). space.confirmations_resumed carries no data.
reason is written for a person: show it as is.
Flow webhooks
A Call webhook step sends a flow.webhook event to the URL set in the step when a contact reaches it. It comes from the flow, not from the endpoints of Settings › Webhooks: no subscription needed.
{
"id": "evt_…",
"type": "flow.webhook",
"created_at": "2026-11-12T09:00:00Z",
"space_id": "…",
"livemode": true,
"data": {
"name": "send_welcome_sms",
"flow": { "id": "…", "name": "Onboarding" },
"step_id": "…",
"run_id": "…",
"contact": {
"id": "…", "email": "jane@example.com", "first_name": "Jane", "last_name": "Doe",
"status": "ACTIVE", "attributes": { "phone": "+33612345678", "plan": "pro" }
},
"event": { "id": "…", "name": "signed_up", "occurred_at": "…", "properties": { … } }
}
}
| Field | Value |
|---|---|
name | The name set in the step |
contact | The contact when the step runs: an attribute set by the step just before is included |
event | The event that started the run. null in a flow started by a list |
test | true on a request sent with Send test request |
- Signature. Same headers and verification, with the space's flow webhook secret as the key. One secret serves every step of the space; the step panel shows it. Admins can regenerate it there: the next calls use the new one.
- Retries. The same as below, but a step is never disabled: each call gives up after its last retry.
- Test requests are sent once, without retries.
Headers
| Header | Value |
|---|---|
Content-Type | application/json |
User-Agent | Mailler-Webhooks/1.0 |
Mailler-Event | The event type, such as email.bounced |
Mailler-Delivery-Id | Id of this delivery, the same on every retry |
Mailler-Signature | t=<unix seconds>,v1=<signature>, see below |
Verify the signature
Check the signature to make sure a request comes from Kula:
- Read the raw request body, before any JSON parsing.
- Split
Mailler-Signatureon,to gett(a timestamp) andv1(the signature). - Compute an HMAC-SHA256 of
<t>.<raw body>with your endpoint secret as the key, in lowercase hexadecimal. The key is the whole secret,whsec_prefix included. - Compare it to
v1in constant time, and reject timestamps more than 5 minutes old to block replays.
import crypto from 'node:crypto'
import express from 'express'
const app = express()
const secret = process.env.KULA_WEBHOOK_SECRET // whsec_...
app.post('/webhooks/kula', express.raw({ type: 'application/json' }), (req, res) => {
const header = req.get('Mailler-Signature') ?? ''
const parts = Object.fromEntries(header.split(',').map(p => p.split('=', 2)))
const timestamp = Number(parts.t)
const body = req.body.toString('utf8')
const expected = crypto.createHmac('sha256', secret).update(`${timestamp}.${body}`).digest('hex')
const valid = parts.v1?.length === expected.length
&& crypto.timingSafeEqual(Buffer.from(parts.v1), Buffer.from(expected))
const fresh = Math.abs(Date.now() / 1000 - timestamp) <= 300
if (!valid || !fresh) return res.sendStatus(400)
const event = JSON.parse(body)
// Queue the work, then answer fast
res.sendStatus(200)
})
import hashlib, hmac, json, os, time
from flask import Flask, request, abort
app = Flask(__name__)
SECRET = os.environ["KULA_WEBHOOK_SECRET"] # whsec_...
@app.post("/webhooks/kula")
def kula_webhook():
header = request.headers.get("Mailler-Signature", "")
parts = dict(p.split("=", 1) for p in header.split(",") if "=" in p)
timestamp = int(parts.get("t", "0"))
body = request.get_data(as_text=True)
expected = hmac.new(SECRET.encode(), f"{timestamp}.{body}".encode(), hashlib.sha256).hexdigest()
if not hmac.compare_digest(parts.get("v1", ""), expected):
abort(400)
if abs(time.time() - timestamp) > 300:
abort(400)
event = json.loads(body)
# Queue the work, then answer fast
return "", 200
express.json(), for example) change the bytes and break the signature. Always verify the raw body.Retries
A delivery succeeds when your endpoint answers any 2xx status within 10 seconds. Redirects are not followed.
Otherwise it retries after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours, then gives up. After 50 failed deliveries in a row, the endpoint is disabled and owners and admins get an email. Enable it again in the dashboard (or with PATCH and "enabled": true) once fixed; failed deliveries can be retried from the dashboard.
Best practices:
- Answer fast. Store the event or put it in a queue, answer
200, then do the work. - Expect duplicates. A delivery can arrive twice. Deduplicate with the event
id(orMailler-Delivery-Id). - Don't rely on order.
email.openedcan arrive beforeemail.delivered. Usecreated_atwhen order matters.
The endpoint object
{
"id": "1f2e3d4c-5b6a-4987-8a7b-6c5d4e3f2a1b",
"spaceId": "3f1c9a52-7b0e-4d8a-9c61-2e5f8b7a4d10",
"test": false,
"url": "https://api.acme.com/webhooks/kula",
"description": "Bounces to our user database",
"eventTypes": ["email.bounced", "email.complained", "contact.unsubscribed"],
"enabled": true,
"consecutiveFailures": 0,
"disabledReason": null,
"createdAt": "2026-10-17T09:30:00Z",
"updatedAt": "2026-10-17T09:30:00Z"
}
spaceId is null for an account endpoint. test is true for an endpoint that receives the events of test spaces.
List endpoints
GET /v1/webhooks
Create an endpoint
POST /v1/webhooks
A space has at most 20 endpoints.
https URL, 2,000 characters at most. Private and local addresses are refused.curl https://api.kulamail.com/v1/webhooks \
-H "Authorization: Bearer ml_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"url": "https://api.acme.com/webhooks/kula",
"description": "Bounces to our user database",
"eventTypes": ["email.bounced", "email.complained", "contact.unsubscribed"]
}'
{
"endpoint": { "id": "1f2e3d4c-…", "url": "https://api.acme.com/webhooks/kula", "enabled": true, "…": "…" },
"secret": "whsec_k3J9x…"
}
The signing secret is returned only here: store it right away. Rotate it in the dashboard.
| Status | Code | When |
|---|---|---|
| 400 | invalid_url | Not https, or a private address |
| 400 | bad_request | Unknown event type, or 20 endpoints already |
Get, update and delete an endpoint
GET /v1/webhooks/{id}returns the endpoint.PATCH /v1/webhooks/{id}changesurl,description,eventTypesorenabled. Fields left out stay as they are. Enabling again resets the failure streak.DELETE /v1/webhooks/{id}answers204.
Account endpoint routes
The same routes under /v1/account/webhooks, with an account key and no X-Space-Id. A space key answers 403.
GET /v1/account/webhookslists the account endpoints of the key's mode.POST /v1/account/webhookscreates one, with the same fields. It takes the mode of the key: a test key (ml_test_) creates a test endpoint. An account has at most 20 account endpoints.GET,PATCHandDELETE /v1/account/webhooks/{id}work as above. An endpoint of the other mode answers404.
curl https://api.kulamail.com/v1/account/webhooks \
-H "Authorization: Bearer ml_your_account_key" \
-H "Content-Type: application/json" \
-d '{
"url": "https://api.acme.com/webhooks/kula",
"eventTypes": ["email.bounced", "email.complained", "contact.unsubscribed"]
}'
The secret is returned only in this answer, as for a space endpoint.