Receive webhook events
Register a marketing or CRM webhook, verify signed deliveries, receive event batches, and investigate delivery failures.
Use webhooks to notify your backend when something happens in Easymailing. A webhook has a scope and subscribes to selected event types of that scope:
- A
marketingwebhook belongs to one audience. It receives member events: subscriptions, groups, campaigns, automations, and SMS. - A
crmwebhook belongs to the whole account and has no audience. It receives the events of contacts, companies, and opportunities, whatever created or changed them: the app, the public API, imports, forms, or integrations.
Each HTTP delivery can contain several events.
This guide registers a webhook through the public API and builds a Node.js receiver that checks the signature before parsing or saving the delivery.
Prepare your endpoint and secret
You need server-side API credentials and
an endpoint that Easymailing can reach. A marketing webhook also needs an
audience IRI; the Quickstart shows how to retrieve an
audience.
Use HTTPS for the public endpoint and create a separate, randomly generated webhook secret. Store the same secret in the webhook configuration and your receiver's environment. It is a shared signing key, separate from your API key. The signature is sent with deliveries; the secret itself is not sent in the delivery headers.
Build and test the receiver below before activating a webhook. If you run it behind a reverse proxy, route the public URL to the receiver and preserve the request body without decoding and re-encoding JSON.
Register the webhook
Once your receiver is ready, use Create a webhook. Replace all placeholders and the example audience IRI. Running this request creates an active webhook in your account.
curl --fail-with-body 'https://api.easymailing.com/webhooks' \
--request POST \
--header 'X-Auth-Token: YOUR_API_KEY' \
--header 'Accept: application/ld+json' \
--header 'Content-Type: application/ld+json' \
--data '{
"title": "Subscription changes",
"audience": "/audiences/11111111-1111-4111-8111-111111111111",
"event_types": ["member_subscribed", "member_unsubscribed"],
"url": "https://integration.example.com/webhooks/easymailing",
"secret": "YOUR_WEBHOOK_SECRET",
"active": true
}'The required fields are title, event_types, url, and secret, plus
audience for a marketing webhook. Set active explicitly: a new webhook is
inactive by default. The audience value is an IRI such as /audiences/{uuid},
not a bare UUID.
scope is marketing when you omit it, so the request above creates a
marketing webhook. To receive CRM events, send "scope": "crm", leave out
audience, and choose crm_* event types:
curl --fail-with-body 'https://api.easymailing.com/webhooks' \
--request POST \
--header 'X-Auth-Token: YOUR_API_KEY' \
--header 'Accept: application/ld+json' \
--header 'Content-Type: application/ld+json' \
--data '{
"title": "CRM changes",
"scope": "crm",
"event_types": ["crm_contact_created", "crm_opportunity_stage_changed"],
"url": "https://integration.example.com/webhooks/easymailing",
"secret": "YOUR_WEBHOOK_SECRET",
"active": true
}'A webhook never mixes the two scopes: every event type must belong to its
scope, a crm webhook rejects an audience, and a marketing webhook requires
one. The scope cannot change after creation; to switch, create another webhook.
A successful creation returns HTTP 201. Save the returned webhook uuid for
configuration and diagnostics. The read schema includes the secret, so treat
configuration responses as sensitive and avoid logging them in full.
To change the configuration, use
Update a webhook
with PUT /webhooks/{uuid}. Send the required configuration fields and the
desired active value. Set active to false to stop collecting new events
for that webhook; do not assume this cancels requests already queued for delivery.
Choose event types
Webhook events in the API Reference lists every
event type, grouped by scope, with its description and the schema of its
event_data. Those pages are generated from the same definitions Easymailing
uses to build the deliveries, so they stay in step with what your endpoint
receives.
Use the exact event names: member_* event types belong to the marketing
scope and crm_* event types to the crm scope. Subscribe only to events your
integration needs. Email subscription and SMS subscription are separate signals.
custom_automation_step is also a marketing event type, but its payload is
the one the Send webhook automation step
defines, so it has no page in Webhook events.
Understand the delivery
Easymailing sends an HTTP POST with Content-Type: application/json and these
headers:
| Header | Meaning |
|---|---|
Easymailing-Webhook-Signature | sha256= followed by the hexadecimal HMAC-SHA256 digest of the exact request body. |
Easymailing-Webhook-Id | UUID of the webhook request record, useful when investigating a delivery. This is not the webhook configuration UUID. |
The body is a JSON array of up to 100 events of the same webhook. Each item has
an event identifier, a date, an event type, and event-specific data. The page of
each event in Webhook events documents its
event_data. You may encounter event_type / event_data
or eventType / eventData. The receiver below accepts either pair and
normalizes it after signature verification. The snake_case form is also shown
in the Help Center webhook examples.
This fictional example illustrates a subscription event. The nested member has been shortened; it is not a captured production delivery.
[
{
"id": "/webhooks/33333333-3333-4333-8333-333333333333/webhook_events/44444444-4444-4444-8444-444444444444",
"date": "2026-09-10T12:00:00+00:00",
"event_type": "member_subscribed",
"event_data": {
"source": "suscriber.source.api",
"subscription_form": null,
"member": {
"id": "/audiences/11111111-1111-4111-8111-111111111111/members/22222222-2222-4222-8222-222222222222",
"audience": "/audiences/11111111-1111-4111-8111-111111111111",
"email": "alex@example.com"
}
}
}
]The event id is distinct from the request UUID in the header. Event identifiers
can be resource IRIs, as illustrated above. Preserve them as strings. The
contents of event_data depend on the event type; do not treat
every delivery as a member subscription or assume it matches a member API
response in full.
The HMAC covers the body only. The request ID header is a diagnostic hint, not an authenticated event identifier. A valid signature also does not prove that a delivery is new: replay handling belongs in your processing logic.
Verify and receive with Node.js
Save this as webhook-server.mjs in a private server directory. It uses native
Node.js modules and has been checked with Node.js 22.22.0.
The receiver saves validated batches to a local inbox before returning HTTP
204. It does not update your application or remove inbox files. A worker must
consume the saved batches. For production, use storage appropriate to your
durability and deployment requirements, such as a database inbox or persistent
queue, before acknowledging delivery.
import { createHmac, randomUUID, timingSafeEqual } from 'node:crypto';
import { mkdir, rename, unlink, writeFile } from 'node:fs/promises';
import { createServer } from 'node:http';
import { join, resolve } from 'node:path';
const secret = process.env.EASYMAILING_WEBHOOK_SECRET;
if (!secret) throw new Error('Set EASYMAILING_WEBHOOK_SECRET');
const inbox = resolve(process.env.EASYMAILING_WEBHOOK_INBOX || 'webhook-inbox');
await mkdir(inbox, { recursive: true, mode: 0o700 });
// Local receiver policy, not an Easymailing payload limit.
const maxBodyBytes = 1024 * 1024;
function verifySignature(rawBody, signature) {
if (typeof signature !== 'string') return false;
const match = /^sha256=([0-9a-f]{64})$/.exec(signature);
if (!match) return false;
const expected = createHmac('sha256', secret).update(rawBody).digest();
const received = Buffer.from(match[1], 'hex');
return timingSafeEqual(expected, received);
}
function isObject(value) {
return value !== null && typeof value === 'object' && !Array.isArray(value);
}
function normalizeBatch(value) {
if (!Array.isArray(value) || value.length === 0) {
throw new Error('Expected an event array');
}
return value.map((event) => {
if (!isObject(event)) throw new Error('Expected an event object');
const snake = Object.hasOwn(event, 'event_type') || Object.hasOwn(event, 'event_data');
const camel = Object.hasOwn(event, 'eventType') || Object.hasOwn(event, 'eventData');
if (snake === camel) throw new Error('Missing or ambiguous event fields');
const type = snake ? event.event_type : event.eventType;
const data = snake ? event.event_data : event.eventData;
if (typeof event.id !== 'string' || !event.id ||
typeof event.date !== 'string' || !event.date ||
typeof type !== 'string' || !type || !isObject(data)) {
throw new Error('Invalid event envelope');
}
return { id: event.id, date: event.date, event_type: type, event_data: data };
});
}
async function saveBatch(events) {
const name = randomUUID();
const temporary = join(inbox, `${name}.tmp`);
try {
await writeFile(temporary, JSON.stringify(events), {
flag: 'wx', mode: 0o600, flush: true,
});
// Workers should only read .json files, after this rename completes.
await rename(temporary, join(inbox, `${name}.json`));
} catch (error) {
await unlink(temporary).catch(() => {});
throw error;
}
}
const server = createServer(async (request, response) => {
let requestId;
const reply = (status) => {
if (requestId) console.info(JSON.stringify({ request_id: requestId, status }));
response.writeHead(status).end();
};
try {
if (request.url !== '/webhooks/easymailing') {
response.writeHead(404).end();
return;
}
if (request.method !== 'POST') {
response.writeHead(405, { Allow: 'POST' }).end();
return;
}
const chunks = [];
let size = 0;
for await (const chunk of request.iterator({ destroyOnReturn: false })) {
size += chunk.length;
if (size > maxBodyBytes) {
request.resume();
response.writeHead(413, { Connection: 'close' }).end();
return;
}
chunks.push(chunk);
}
const rawBody = Buffer.concat(chunks);
if (!verifySignature(rawBody, request.headers['easymailing-webhook-signature'])) {
response.writeHead(401).end();
return;
}
const headerId = request.headers['easymailing-webhook-id'];
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
if (typeof headerId === 'string' && uuid.test(headerId)) requestId = headerId;
let events;
try {
events = normalizeBatch(JSON.parse(rawBody.toString('utf8')));
} catch {
reply(400);
return;
}
await saveBatch(events);
reply(204);
} catch {
// Keep secrets, member data, and raw payloads out of general logs.
console.error('Webhook receiver failed');
if (!response.headersSent) reply(500);
else response.end();
}
});
server.listen(8787, '127.0.0.1');Set EASYMAILING_WEBHOOK_SECRET to the same value used when registering the
webhook, then run:
node webhook-server.mjsThe example listens on loopback. Route your public HTTPS endpoint to
http://127.0.0.1:8787/webhooks/easymailing. Keep its inbox outside the web root
and restrict access to stored member data. If you choose an existing inbox
directory, ensure its permissions are already restricted.
The size limit is an example receiver policy. Choose a limit that accommodates the event batches you expect, and align it with your reverse proxy. The receiver normalizes only the envelope keys; validate any nested fields your worker uses before acting on them.
The example logs the request ID and HTTP result after signature verification, when the header contains a valid UUID. Keep ingress logs too when investigating rejected signatures or requests that do not reach this handler.
Process batches without repeating side effects
Treat receipt and business processing as separate steps:
- Verify the signature over the original bytes, validate the entire batch, and save it before sending a successful response.
- In your worker, dispatch each item by its
event_type. Handle unknown event types explicitly, for example by retaining them for review. - Track processed event IDs in persistent storage, scoped to the webhook configuration. Record completion atomically with your own database changes. For external side effects, use the destination's idempotency mechanism when one is available.
- Make state updates tolerate delayed or reordered events. When you need the latest member state, retrieve it through the public API rather than assuming arrival order represents current state.
These are integration recommendations. The public contract does not establish exactly-once delivery, ordering, a fixed delivery latency, or a retry schedule. Deduplicating an event ID prevents repeating that recorded event; it does not establish that separate events represent different business actions. A failed delivery may be retried, so do not return a successful response before accepting responsibility for the whole batch.
Investigate deliveries
Start with Get a webhook
and check its url, scope, audience, event_types, and active value.
There are two related diagnostic resources:
| Resource | Use it to inspect |
|---|---|
| Webhook events | Individual events, their data, and the related webhook_request. |
| Webhook requests | Delivery payload, stored HTTP response, success state, and related webhook_events. |
For example, list requests for your webhook:
curl --fail-with-body \
'https://api.easymailing.com/webhooks/33333333-3333-4333-8333-333333333333/webhook_requests?page=1&itemsPerPage=30' \
--header 'X-Auth-Token: YOUR_API_KEY' \
--header 'Accept: application/ld+json'Use Easymailing-Webhook-Id from your receiver logs to select
Get a webhook request:
GET /webhooks/{webhookUuid}/webhook_requests/{uuid}. The first UUID identifies
your configuration; the second identifies the request record.
Check payload, response_status_code, response_body, successful, and
updated_at together. A request can hold multiple events and be retried using
the same request record, whose stored HTTP result is updated. It is not a
complete per-attempt timeline. Although the schema declares retry_count, the
current API response mapping does not populate it from the delivery counter;
use your ingress and receiver logs to investigate attempts.
To investigate a particular event, follow its webhook_request link from
Get a webhook event.
The API event resource has its own fields and wraps the saved event in
event_data; it is not the entire incoming delivery array. Follow
pagination when inspecting older records.
| Symptom | What to check |
|---|---|
| No new events | Confirm the webhook is active, its scope and event types match the change, and, for a marketing webhook, that the audience matches. A data edit does not necessarily change subscription status. |
| Signature rejected | Use the webhook secret, read Easymailing-Webhook-Signature, retain sha256=, and hash the original body bytes. Whitespace changes invalidate the signature. |
HTTP 400 from the example receiver | Check that the signed payload is a JSON array and every event has a consistent envelope. Do not send a single object with a data property. |
HTTP 413 from the example receiver | Review the local body limit and proxy limits against the batch size. |
HTTP 404 or 410 from your endpoint | Fix the URL or routing and check active: these response codes deactivate the webhook in the current delivery implementation. |
| Request succeeded but your system did not update | A successful receipt does not prove worker completion. Inspect the saved batch and your processing records. |
Keep diagnostic logs restricted and record correlation identifiers and outcomes without copying secrets or full member payloads into general application logs.
Test before activating
Use fictional member data and a test secret in a local simulation. Check a correct signature, a changed body with the original signature, a wrong secret, a missing header, invalid JSON, and a multi-event batch. Only the correct, valid batch should reach storage. Also exercise storage failures so the receiver cannot acknowledge a batch that it failed to save.
Replay a validated batch through your worker to check your duplicate-handling policy, and test delayed subscription changes before relying on arrival order. After local checks, verify the deployed receiver's HTTPS routing and your processing path before enabling the webhook configuration.