Skip to main content
About this page · Updated 2026-11-28 00:36 UTC

What this page is: Email delivery webhooks for Motorical — configure endpoints, validate X-Motorical-Signature, process bounce and delivery events.

How far to trust this page: the build checked 1 names, paths, tools, scopes and error codes against the real product (0 do not match). Reviewed claim by claim on 2026-10-22 (documentation truth audit).

Updated 2026-11-28 00:36 UTCLatest change: Webhooks: signed timestamps protect against replayed deliveriesRecently updated pages

Webhooks

Use Motorical delivery webhooks to push real-time email events to your server — deliveries, bounces, complaints, and more.

Managing Webhooks​

All webhook endpoints require the webhooks.manage scope.

List Webhooks​

curl -H "Authorization: Bearer $TOKEN" \
"$BASE_URL/motor-blocks/$BLOCK_ID/webhooks"

Response: Array of webhook endpoints with id, url, events, enabled, failure_count, last_delivery_at, and created_at.

Create a Webhook​

curl -X POST -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/webhook","events":["message.delivered","message.bounced"]}' \
"$BASE_URL/motor-blocks/$BLOCK_ID/webhooks"

If events is omitted, the webhook subscribes to all six events listed under Available Events. Pass an explicit events array for a subset — in particular, omit message.processed and message.deferred unless your application handles intermediate states.

The 201 response returns the signing secret once — it is never retrievable again:

{
"success": true,
"data": {
"id": "9c2f0d81-4b6e-4d2a-9f11-3a7e5c0b8d42",
"url": "https://example.com/webhook",
"events": ["message.delivered", "message.bounced"],
"enabled": true,
"created_at": "2026-08-25T12:00:00.000Z",
"secret": "…48 hex chars…",
"secretMasked": "ab12…"
},
"message": "Webhook created. The full \"secret\" is shown once — store it now for signature verification (X-Motorical-Signature)."
}

Store data.secret immediately. It is the key for the HMAC-SHA256 verification below; losing it means deleting and recreating the webhook.

Update a Webhook​

curl -X PUT -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/new-url","enabled":true}' \
"$BASE_URL/motor-blocks/$BLOCK_ID/webhooks/$WEBHOOK_ID"

Updatable fields: url, events (array), enabled (boolean).

Delete a Webhook​

curl -X DELETE -H "Authorization: Bearer $TOKEN" \
"$BASE_URL/motor-blocks/$BLOCK_ID/webhooks/$WEBHOOK_ID"

Test a Webhook​

Send a test delivery to verify your endpoint is reachable:

curl -X POST -H "Authorization: Bearer $TOKEN" \
"$BASE_URL/motor-blocks/$BLOCK_ID/webhooks/$WEBHOOK_ID/test"

Returns 202 Accepted with a queued test delivery.

Delivery History​

View recent webhook deliveries with status and latency:

curl -H "Authorization: Bearer $TOKEN" \
"$BASE_URL/motor-blocks/$BLOCK_ID/webhooks/$WEBHOOK_ID/deliveries?limit=50"

Parameters:

ParameterDescription
limitMax deliveries to return (1–200, default 50)

Response: Array of deliveries with eventType, status, attempts, error, latencyMs, createdAt, and deliveredAt.

Signature Verification​

Every delivery is a POST with these headers:

HeaderValue
X-Motorical-TimestampWhen the delivery was signed, in Unix seconds
X-Motorical-Signature-V2HMAC-SHA256 of <timestamp>.<raw request body>, keyed with the webhook's secret, hex-encoded. Verify this one.
X-Motorical-Signaturev1: HMAC-SHA256 of the raw body alone. Still sent so existing receivers keep working; it does not protect against replays.
X-Motorical-EventThe event type, for example message.delivered
Content-Typeapplication/json
User-AgentMotorical-Webhooks/1.0

Verify the v2 signature before you trust the payload:

  • Use the exact bytes you received, not JSON you parsed and serialised again (whitespace, key order or escaping can differ, and a valid delivery would then fail).
  • Reject a timestamp more than 300 seconds from your clock. Because the timestamp is signed, a captured delivery cannot be replayed later, and the timestamp cannot be changed without breaking the signature.
  • Compare in constant time, and treat a missing or wrong-length header as a failed check, not an error. Answer 401 when the check fails.

A delivery that is retried is signed again with a new timestamp, so it passes. Process each event once anyway (remember the message id together with the event type), because a retry after a timeout can repeat an event you already handled.

Each sample below runs in our test suite against the signing code our webhook worker uses, including a replayed and a tampered delivery.

const crypto = require('crypto');

// rawBody: the exact bytes of the request body (a Buffer), before any JSON parsing.
// Headers: X-Motorical-Timestamp and X-Motorical-Signature-V2. toleranceSeconds: how far the timestamp may be from now.
function verifyMotoricalSignature(rawBody, timestampHeader, signatureHeader, secret, toleranceSeconds = 300) {
const timestamp = Number(timestampHeader);
if (!Number.isInteger(timestamp) || Math.abs(Date.now() / 1000 - timestamp) > toleranceSeconds) return false; // stale or replayed
const expected = crypto.createHmac('sha256', secret).update(`${timestamp}.`).update(rawBody).digest('hex');
const received = String(signatureHeader || '');
if (received.length !== expected.length) return false;
return crypto.timingSafeEqual(Buffer.from(received), Buffer.from(expected));
}

// Express: keep the raw body for this route.
// app.post('/webhooks/motorical', express.raw({ type: 'application/json' }), (req, res) => {
// const ok = verifyMotoricalSignature(req.body, req.get('X-Motorical-Timestamp'), req.get('X-Motorical-Signature-V2'), process.env.MOTORICAL_WEBHOOK_SECRET);
// if (!ok) return res.status(401).end();
// const event = JSON.parse(req.body.toString('utf8'));
// res.status(200).end(); // answer fast, then process event asynchronously
// });

Available Events​

EventDescription
message.processedAccepted by the gateway and handed to delivery — an intermediate event, not a final outcome
message.deferredDelivery temporarily delayed; a retry is scheduled
message.deliveredAccepted by the recipient's server
message.bouncedBounced (hard or soft)
message.failedPermanent delivery failure
message.complainedRecipient marked the email as spam

Monitoring Webhook Health​

Check delivery statistics for a webhook endpoint:

curl -H "Authorization: Bearer $TOKEN" \
"$BASE_URL/motor-blocks/$BLOCK_ID/webhooks/$WEBHOOK_ID/stats?hours=24"

Response includes: delivered count, failed count, queued count, failure rate, and average latency.

Best Practices​

  • Respond quickly — return a 2xx response within 10 seconds (the delivery times out after that)
  • Process asynchronously — queue webhook payloads for background processing
  • Verify signatures — always validate X-Motorical-Signature
  • Handle retries — Motorical retries a failed delivery after 1, 5, 15 and 60 minutes, and disables the webhook after 10 consecutive failures (a success resets the count)
  • Use HTTPS — webhook URLs must use TLS