Webhooks

Overview

Webhooks send an event to your server each time something happens to your orders, so you don't have to keep asking the API. Every request is signed, so you can check it really comes from us.

Add an endpoint

An endpoint is a URL of yours that receives events. Add one in the app under Settings › Webhooks. Only workspace owners and admins can add or change endpoints.

  • The URL must start with https:// and use a domain name, not an IP address (at most 2,000 characters). The name must point only to public internet addresses: otherwise it is saved, but every delivery to it fails.
  • A workspace can have up to 5 endpoints. Each one gets the events you picked for it, of its own workspace only: a main workspace's endpoint does not get its sub-workspaces' events.
  • Pick the events the endpoint gets: order created, order updated, order cancelled, or all three.
  • Each endpoint has its own signing secret (whsec_sm_...), shown once when you create it. You need it to check the signature.

Events

Event`event` in the bodySent when
Order createdorder_createdA new order (subscription) is paid.
Order updatedorder_status_changedOne provider part of an order (Google, Outlook or SMTP) changes status, e.g. to active.
Order cancelledorder_cancelledAn order is cancelled. It keeps running until ends_at.

Ignore events you don't handle and still answer 2xx.

What we send

Events are sent in the same format as API v1: the body has event, timestamp and data, and event is one of the names under Events above.

One HTTPS POST per event and endpoint, with a JSON body of three parts: event (the event name), timestamp (when it happened, UTC, ISO 8601) and data (the details, see each event's page).

Example request
POST /webhooks/scaledmail HTTP/1.1
Content-Type: application/json
User-Agent: ScaledMail-Webhooks/1
X-ScaledMail-Event: order_status_changed
X-ScaledMail-Delivery: 0192c3f1-6b8a-7c2d-8e3f-4a5b6c7d8e9f
X-ScaledMail-Signature: 9f2c...e1a7

{"event":"order_status_changed","timestamp":"2026-11-14T10:39:43.996Z","data":{...}}
HeaderValue
Content-Typeapplication/json
User-AgentScaledMail-Webhooks/1
X-ScaledMail-EventThe event name, the same as event in the body.
X-ScaledMail-DeliveryA unique id for this delivery (a UUID).
X-ScaledMail-SignatureThe signature of the body. See Check the signature below.

The signature

  • The X-ScaledMail-Signature header holds an HMAC-SHA256 of the raw request body, written as lower-case hex (64 characters).
  • The token is the endpoint's whole signing secret, including the whsec_sm_ part.
  • Only the body is signed. There is no timestamp in the signed text for now (a timestamped signature is coming with the v2 event format).

Check the signature

  • Use the body exactly as received, as bytes, before any JSON parsing. Parsing and printing the JSON again changes it, and the signature won't match.
  • Make the HMAC-SHA256 of those bytes with your secret, as hex.
  • Compare it with the header using a timing-safe compare, never ==.
  • If they differ, answer 401 and ignore the request.

The signature doesn't include a time, so someone who has a copy of a real request could send it again. Skip X-ScaledMail-Delivery ids you have already handled.

Node.js

Node.js (Express)
import crypto from "node:crypto";
import express from "express";

const SECRET = process.env.SCALEDMAIL_WEBHOOK_SECRET; // whsec_sm_...
const app = express();

// Read the body as raw bytes: the signature is made over the exact bytes we send.
app.post("/webhooks/scaledmail", express.raw({ type: "application/json" }), (req, res) => {
  const expected = crypto.createHmac("sha256", SECRET).update(req.body).digest("hex");
  const given = req.get("x-scaledmail-signature") ?? "";
  const a = Buffer.from(expected);
  const b = Buffer.from(given);
  if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
    return res.status(401).end();
  }
  const event = JSON.parse(req.body.toString("utf8"));
  queue.add(event); // your own queue: skip delivery ids you have already handled
  res.status(200).end();
});

app.listen(3000);

Python

Python (Flask)
import hashlib
import hmac
import json
import os

from flask import Flask, abort, request

SECRET = os.environ["SCALEDMAIL_WEBHOOK_SECRET"]  # whsec_sm_...
app = Flask(__name__)


@app.post("/webhooks/scaledmail")
def scaledmail_webhook():
    raw = request.get_data()  # the exact bytes we sent, before any JSON parsing
    expected = hmac.new(SECRET.encode(), raw, hashlib.sha256).hexdigest()
    given = request.headers.get("X-ScaledMail-Signature", "")
    if not hmac.compare_digest(expected, given):
        abort(401)
    event = json.loads(raw)
    queue.put(event)  # your own queue: skip delivery ids you have already handled
    return "", 200

Roll the secret

Roll an endpoint's secret in the app under Settings › Webhooks when it may have leaked or as routine. The new secret is shown once.

  • The old secret stops working at once: there is no overlap. Every event sent after the roll, including ones already waiting, is signed with the new secret only.
  • Have your server ready to accept the new secret before you roll, or roll at a quiet time. An event that fails meanwhile is not resent: read the order again with GET /orders/{id}.

Store the secret like a password: in your secret store, never in code or a web page.

Answer fast

  • Check the signature, save the event (or put it on a queue), and answer any 2xx status. Do the real work afterwards.
  • Any other status, a redirect, or no answer within 10 seconds counts as failed. We don't follow redirects.
  • We don't read your answer body.

Delivery

Events are sent within a few seconds. For now each event gets one try: a failed delivery is not sent again automatically. When a delivery to your endpoint fails, the events picked up together with it wait about a minute, then each gets its one try; later events are sent as usual, so they can arrive out of order. The app shows the result of each endpoint's last delivery under Settings › Webhooks.

Because a failed event is not resent, don't rely on webhooks alone. If your endpoint was down, read the object again, e.g. GET /orders or GET /orders/{id}, for its latest state.

  • Order: events for one endpoint are usually sent in the order they happened, but this is not guaranteed. Use timestamp, or read the object again, when the latest state matters.
  • Duplicates: in rare cases the same event arrives twice, e.g. when our support team resends a failed delivery. A resent delivery keeps its X-ScaledMail-Delivery id, so skip ids you have already handled.