The Traffic Mill Webhook Protocol — v1.1
This protocol connects The Traffic Mill to any website or CMS that can answer HTTP requests. It has two modes; you choose one per website in Websites → your site → Connection.
| Mode | What you build | What The Traffic Mill can do |
|---|---|---|
| Publish only | One endpoint that receives signed articles (section 3) | Publish new articles, and update the articles it published by sending them again |
| Full sync | Five endpoints: health, list, get, create, update (sections 4–7) | Everything above, plus import the posts already on your site, keep them in sync, optimize and interlink them |
Publish only is the quickest start (comparable to a blog webhook). Upgrade to full sync when you want
your existing posts optimized; articles already published are matched, not duplicated
(ttm_id).
Everything here is enough to build a connector without access to our code.
1. Overview
In publish-only mode you give us one endpoint URL (for example
https://www.example.com/api/traffic-mill) and we POST signed events to exactly that URL.
In full-sync mode you give us a base URL and we send signed requests to these paths under it:
| Operation | Method & path | Required |
|---|---|---|
| Health / capabilities | GET {base}/health |
yes |
| List articles | GET {base}/articles |
yes |
| Get one article | GET {base}/articles/{id} |
yes |
| Create article | POST {base}/articles |
if create_article capability |
| Update article | PUT {base}/articles/{id} |
if update_article capability |
Requirements:
- HTTPS only with a valid public certificate. Plain HTTP endpoints are rejected.
- The host must resolve to a public IP address. Private, loopback and link-local addresses are refused (SSRF protection), and redirects are not followed — return the final URL directly.
- Ports 443 and 8443 are supported.
- Trailing slashes (full sync). If your site redirects
/pathto/path/(Next.jstrailingSlash, most WordPress permalink settings), end the base URL with a slash, e.g.https://www.example.com/api/traffic-mill/. Every request path then ends with a slash too:{base}health/,{base}articles/,{base}articles/{id}/(the query string follows the slash). A base URL without a trailing slash, or a bare domain, gets paths without one. The connection test tells you when a redirect only adds or removes a slash. In publish-only mode we post to the URL exactly as entered, so enter it the way your site serves it. - Respond within 15 seconds. Responses over 10 MB are rejected.
- All bodies are JSON (
Content-Type: application/json; charset=utf-8).
2. Authentication & signatures
When you connect a website, The Traffic Mill shows you:
- a Website ID (
ws_…) — sent in every request, identifies the connection; - a signing secret (
ttm_whsec_…) — shared secret for HMAC signatures. Store it like a password.
Request headers
| Header | Example | Meaning |
|---|---|---|
X-TTM-Website-Id |
ws_3f1c… |
Your Website ID |
X-TTM-Timestamp |
1764892800 |
Unix time (seconds) when the request was signed |
X-TTM-Request-Id |
0b8f…-uuid |
Unique per request (also per retry attempt) |
X-TTM-Idempotency-Key |
pub_9a2… |
POST/PUT only — identical for all retries of the same logical operation |
X-TTM-Protocol-Version |
1.1 |
Protocol version |
X-TTM-Signature |
v1=5d2a… |
HMAC signature(s), see below |
User-Agent |
TheTrafficMill-Webhook/1.1 |
Computing the signature
body_hash = lowercase hex SHA-256 of the raw request body ("" for GET → e3b0c442…b855)
signed_payload = timestamp + "." + request_id + "." + METHOD + "." + path_and_query + "." + body_hash
signature = lowercase hex HMAC-SHA256(secret, signed_payload)
header = "v1=" + signature
path_and_queryis the request target exactly as received, e.g./api/traffic-mill/articles?limit=50&cursor=abc.- During secret rotation the header carries two signatures separated by a comma
(
v1=<new>,v1=<old>) for 24 hours. Accept the request if any signature matches a secret you hold, so you can update your secret without downtime.
Verification checklist (you must do all of these)
- Reject if
X-TTM-Website-Idis not yours. - Reject if
|now − X-TTM-Timestamp| > 300seconds. - Recompute the signature from the raw body bytes and compare with a constant-time function.
- Replay protection: remember each
X-TTM-Request-Idfor at least 10 minutes and reject repeats. - Respond
401on any failure, with no detail about which check failed.
Node.js example
import crypto from "node:crypto";
const SECRET = process.env.TTM_SIGNING_SECRET;
const WEBSITE_ID = process.env.TTM_WEBSITE_ID;
const seen = new Map(); // requestId -> expiry; use Redis/DB in production
export function verifyTrafficMillRequest(req, rawBody) {
const h = (n) => req.headers[n.toLowerCase()];
if (h("X-TTM-Website-Id") !== WEBSITE_ID) return false;
const ts = Number(h("X-TTM-Timestamp"));
if (!Number.isFinite(ts) || Math.abs(Date.now() / 1000 - ts) > 300) return false;
const requestId = h("X-TTM-Request-Id");
if (!requestId || seen.has(requestId)) return false;
const bodyHash = crypto.createHash("sha256").update(rawBody ?? "").digest("hex");
const payload = `${ts}.${requestId}.${req.method}.${req.originalUrl}.${bodyHash}`;
const expected = crypto.createHmac("sha256", SECRET).update(payload).digest("hex");
const provided = String(h("X-TTM-Signature") ?? "")
.split(",")
.map((s) => s.trim().replace(/^v1=/, ""));
const ok = provided.some(
(sig) => sig.length === expected.length && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected)),
);
if (ok) seen.set(requestId, Date.now() + 600_000);
return ok;
}
PHP example
function ttm_verify(string $secret, string $websiteId, string $rawBody): bool {
$h = fn($n) => $_SERVER['HTTP_' . strtoupper(str_replace('-', '_', $n))] ?? '';
if (!hash_equals($websiteId, $h('X-TTM-Website-Id'))) return false;
$ts = (int) $h('X-TTM-Timestamp');
if (abs(time() - $ts) > 300) return false;
$rid = $h('X-TTM-Request-Id');
if (ttm_request_id_seen($rid)) return false; // your replay store (DB/cache, keep 10 minutes)
$payload = $ts . '.' . $rid . '.' . $_SERVER['REQUEST_METHOD'] . '.' . $_SERVER['REQUEST_URI'] . '.' . hash('sha256', $rawBody);
$expected = hash_hmac('sha256', $payload, $secret);
foreach (explode(',', $h('X-TTM-Signature')) as $sig) {
if (hash_equals($expected, preg_replace('/^v1=/', '', trim($sig)))) return true;
}
return false;
}
3. Publish-only mode
One endpoint, POST only. Every request carries the signature headers from section 2 (verify them the
same way, including replay protection) and a JSON body with an event field. Respond within 15 seconds;
if your import is slow, accept the article, respond, and finish in the background, but only after you
have recorded the article's id, so a retry finds it.
ping
Sent by the connection test. Change nothing.
{ "event": "ping" }
Respond 200:
{
"status": "ok",
"protocol_version": "1.1",
"cms": "next-sanity",
"capabilities": { "featured_image_url": true, "categories": true }
}
article.publish
{
"event": "article.publish",
"article": {
"id": "8c0f6f0e-2b0e-4c7e-9a43-3f5d2f1f8e21",
"title": "…", "slug": "…", "content_html": "…", "excerpt": "…",
"meta_title": "…", "meta_description": "…", "canonical_url": null,
"featured_image": { "url": "https://<storage>/article-images/…webp", "alt": "…" },
"categories": ["Guides"], "tags": [], "author": null,
"status": "published", "publish_at": null
}
}
Rules:
article.idis our ID for the article and never changes. Store it on your post.- Create or update by
id. The first time you see anid, create a post. Every later event with the sameidupdates that post (title, body, SEO fields, image, categories). Never match on the slug: two different articles may ask for the same slug — give the second one a free variant such asslug-2. - Keep the URL. On an update, keep the post's current slug and URL unless the article has
"change_slug": true(sent only when the user explicitly asks to change it). - Idempotency. Retries of the same send carry the same
X-TTM-Idempotency-Key; applying the same article twice must leave one post. - Only articles we published can be updated this way. We never touch other posts on your site, and we can't see edits made on your site: an update replaces the post's content with ours.
Respond 200 or 201:
{ "data": { "id": "1842", "url": "https://www.example.com/blog/how-to-choose-running-shoes/", "status": "published" } }
| Field | Notes |
|---|---|
url |
Required. The post's public URL (used for Search Console and internal links). |
id |
Optional. Your own ID for the post, if your CMS has one. Lets an upgrade to full sync link the post directly. |
status |
Optional. published, draft, scheduled or private, if it differs from what we sent. |
Errors use the status codes in section 6 (400/422 for an invalid article, 401 for a bad
signature, 5xx for temporary failures, which we retry).
4. Full sync mode: endpoints
GET {base}/health
{
"status": "ok",
"protocol_version": "1.1",
"cms": "custom-laravel",
"capabilities": {
"list_articles": true,
"get_article": true,
"create_article": true,
"update_article": true,
"update_slug": false,
"featured_image_url": true,
"categories": true
}
}
featured_image_url: true means you can download an image from a URL we send and attach it.
update_slug: true means you allow slug changes (we only send them when a user explicitly asks).
GET {base}/articles
Query parameters:
| Param | Meaning |
|---|---|
limit |
Page size requested (1–100). You may return fewer. |
cursor |
Opaque cursor from the previous page's next_cursor. Absent on the first page. |
updated_since |
ISO-8601. When present, return only articles with updated_at >= updated_since (incremental sync). |
Return published articles, ordered stably (e.g. by updated_at, id):
{ "data": [ { …article… }, { …article… } ], "next_cursor": "eyJpZCI6MTg0Mn0" }
next_cursor: null means the last page. Cursors must remain valid for at least 1 hour.
GET {base}/articles/{id}
200 { "data": { …article… } }, or 404 if it no longer exists (we then mark it deleted).
POST {base}/articles
Request body:
{
"title": "…", "slug": "…", "content_html": "…", "excerpt": "…",
"meta_title": "…", "meta_description": "…", "canonical_url": null,
"featured_image": { "url": "https://<storage>/article-images/…webp", "alt": "…" },
"categories": ["Guides"], "tags": [], "author": null,
"status": "published", "publish_at": null
}
Respond 201 { "data": { …created article… } }. Idempotency: if you receive a request with an
X-TTM-Idempotency-Key you have already processed, return the article created the first time instead
of creating a duplicate.
PUT {base}/articles/{id}
Partial update — only fields present in the body change. The URL and id must not change unless the
body includes slug (sent only when the user explicitly requests a slug change and you advertise
update_slug).
{ "content_html": "…", "meta_description": "…", "if_unmodified_since": "2026-11-20T14:31:07Z" }
If if_unmodified_since is present and the article's current updated_at is later, the article was
edited on your site since we read it: respond 409 and do not apply the update. We will then
show the user a conflict instead of overwriting their edit.
Respond 200 { "data": { …updated article… } }. Idempotency keys apply as for POST.
5. Article object
{
"id": "1842",
"url": "https://www.example.com/blog/how-to-choose-running-shoes",
"slug": "how-to-choose-running-shoes",
"title": "How to Choose Running Shoes",
"content_html": "<p>…</p><h2>…</h2>",
"excerpt": "A practical guide…",
"meta_title": "How to Choose Running Shoes (2026 Guide)",
"meta_description": "Fit, cushioning and…",
"canonical_url": null,
"featured_image": { "url": "https://cdn.example.com/shoes.jpg", "alt": "Runner tying shoes" },
"categories": ["Guides"],
"tags": ["running", "shoes"],
"author": "Sam Lee",
"status": "published",
"published_at": "2026-03-02T09:00:00Z",
"updated_at": "2026-11-20T14:31:07Z"
}
| Field | Type | Notes |
|---|---|---|
id |
string (numbers are accepted) | Stable external ID. Must never change. |
url |
absolute URL | Public URL of the article. If it changes, we record the change. |
slug |
string | null | |
title |
string | Required |
content_html |
string | Article body HTML (without the page template). Max 2 MB. |
excerpt, meta_title, meta_description, canonical_url |
string | null | |
featured_image |
{url, alt} | null |
|
categories, tags |
string[] | Names |
author |
string | null | |
status |
published | draft | scheduled | private |
Only published articles are imported by default |
published_at |
ISO-8601 | null | |
updated_at |
ISO-8601 with timezone | Required. Must change whenever content or metadata changes. Used for incremental sync and conflict detection. |
ttm_id |
UUID | null | The article.id we sent if the post was created in publish-only mode. Lets us link it after you switch to full sync instead of importing a duplicate. |
Unknown fields are ignored. Content is sanitized on our side (scripts, styles, iframes and event handlers are removed), so send plain article HTML.
6. Status codes & errors
| Status | Meaning | Our behaviour |
|---|---|---|
| 2xx | Success | Response body validated against this spec |
| 400 / 422 | Invalid request | Not retried; shown to the user |
| 401 / 403 | Signature or permission failure | Not retried; connection marked as error |
| 404 | Not found | Article marked deleted (GET) / not retried |
| 409 | Conflict | Not retried; conflict shown to the user |
| 429 | Rate limited | Retried, honouring Retry-After |
| 5xx, timeouts, network errors | Temporary failure | Retried up to 3 times with exponential backoff; then the background job retries later |
Error body (optional, recommended): { "error": { "code": "invalid_slug", "message": "…" } }.
7. Synchronization semantics (full sync)
- Initial import: all published articles, page by page.
- Incremental sync (daily by default):
updated_since= start of the last successful sync minus 5 minutes. - Full reconciliation (weekly): lists everything; articles we know about that are no longer returned are marked deleted on site (never deleted in The Traffic Mill).
- Conflict detection: we hash each article's content and metadata. If an article changed on your site while it also has unpublished edits in The Traffic Mill, we keep both and ask the user which to keep — your site's version is never silently overwritten.
8. Secret rotation
Rotating the secret in The Traffic Mill generates a new one immediately. For 24 hours we sign with
both secrets (v1=<new>,v1=<old>). Update your connector within that window.
9. Testing your connector
Publish only: the test sends one signed ping event and publishes nothing.
Full sync:
In The Traffic Mill: Websites → your site → Connection → Test connection. The test console calls
/health, lists one page of articles and fetches one article, showing status codes, timings and
validation errors for each step. Every call is also recorded in the webhook log.