Skip to content

Receive webhooks

When you publish an entry or upload media, Hako CMS sends a webhook (an HTTP POST) to the URL you set. This page explains how to receive webhooks on your own server, verify that they really came from Hako CMS, and avoid processing the same notification twice when it is resent.

If you only want to trigger a Vercel or Netlify build, you do not need a receiving server. In the webhook’s [種類](Type), select [Vercel(Deploy Hook)](Vercel (Deploy Hook)) or [Netlify(Build Hook)](Netlify (Build Hook)), and enter the build hook URL.

  • You have created a webhook in the admin. Set [種類](Type) to [カスタム](Custom)
  • You have set the webhook’s [署名のシークレット](Signing secret) (8–256 characters). Put the secret on the receiving server too
  • The receiving URL is reachable from the internet. https:// is recommended. Webhooks cannot be sent to private addresses, such as an internal company network

A webhook arrives in this form.

POST /your/endpoint HTTP/1.1
Content-Type: application/json
User-Agent: Hako-Webhook/0.1.0
X-HAKOCMS-Event: entry.published
X-HAKOCMS-Delivery: d1e2f3a4b5c6
X-HAKOCMS-Signature: 9f2c4e1b7a0d3c5e8f6a1b2c3d4e5f60718293a4b5c6d7e8f9a0b1c2d3e4f5a6

The body is JSON. Its shape is described below, in “Body: entry events” and the following sections.

Header Contents
X-HAKOCMS-Event The event name
X-HAKOCMS-Delivery The delivery ID. It does not change when resent
X-HAKOCMS-Signature The signature. Added only when you set [署名のシークレット](Signing secret)
[カスタムヘッダー](Custom headers) Headers you added to the webhook

To receive webhooks, do the following:

  1. Before you parse the body as JSON, keep it as the raw bytes you received.
  2. Compute HMAC-SHA256 from the body bytes and the secret, and compare it with X-HAKOCMS-Signature. If they do not match, return 401 and stop.
  3. Return 2xx within 10 seconds. Do heavy work after you return.
  4. Look at deliveryId, and do nothing if you have already processed it.

Here is an example server in Node.js (22 or later) that does these four things. It uses no external packages. Save it as server.mjs.

import { createServer } from "node:http";
import { createHmac, timingSafeEqual } from "node:crypto";
const secret = process.env.HAKO_WEBHOOK_SECRET;
// Processed deliveryIds. In production, keep them in a DB or similar
const handled = new Set();
function verify(rawBody, signature) {
if (typeof signature !== "string") return false;
const expected = createHmac("sha256", secret)
.update(rawBody)
.digest("hex");
return (
expected.length === signature.length &&
timingSafeEqual(Buffer.from(expected), Buffer.from(signature))
);
}
function handle(payload) {
// Rebuild the site, purge caches, and so on here
console.log(payload.event, payload.contentType ?? "", payload.id ?? "");
}
createServer((req, res) => {
const chunks = [];
req.on("data", (chunk) => chunks.push(chunk));
req.on("end", () => {
const rawBody = Buffer.concat(chunks);
if (!verify(rawBody, req.headers["x-hakocms-signature"])) {
res.writeHead(401).end();
return;
}
const payload = JSON.parse(rawBody.toString("utf8"));
// Return 2xx first, and do heavy work later
res.writeHead(204).end();
// If the same delivery arrives again as a resend, do nothing
if (handled.has(payload.deliveryId)) return;
handled.add(payload.deliveryId);
handle(payload);
});
}).listen(3000);

Replace <secret> with the webhook’s [署名のシークレット](Signing secret), and start the server.

ターミナルウィンドウ
HAKO_WEBHOOK_SECRET='<secret>' node server.mjs

Compute the signature over the raw bytes you received. If you parse the JSON and turn it back into a string, the spaces and key order change, and the signature does not match. In frameworks such as Express, make sure you can get the body before JSON parsing (in Express, express.raw({ type: "application/json" })).

To compare, use timingSafeEqual, not ===. This prevents the signature from being guessed from how long the comparison takes.

With the server running, send a signed request from another terminal. Replace <secret> with the same value you used to start the server.

ターミナルウィンドウ
body='{"event":"ping","space":"blog","deliveryId":"d1"}'
sig=$(printf '%s' "$body" \
| openssl dgst -sha256 -hmac '<secret>' | sed 's/^.* //')
curl -i -X POST http://localhost:3000 \
-H "Content-Type: application/json" \
-H "X-HAKOCMS-Signature: $sig" \
-d "$body"

If you get HTTP/1.1 204 No Content and the server’s terminal shows ping, signature verification works. If you change X-HAKOCMS-Signature and send again, you get 401.

Put the server somewhere reachable from the internet, enter its URL in the webhook’s [送信先の URL](Destination URL), and then send from Hako CMS.

  1. In the left menu of the admin, click [Webhook](Webhooks).
  2. Click the webhook for your receiving server.
  3. Click [テストの送信](Send test).

A ping event is sent right away, and the result is shown. If [送信履歴](Delivery history) shows [成功](Succeeded), you are receiving webhooks. If it shows [失敗](Failed), [応答](Response) shows the status and the start of the body that your server returned. If the connection failed, the reason is shown (timed out, connection refused, private network address is not allowed, and so on).

If a webhook is not delivered successfully, Hako CMS sends it again.

  • It fails if anything other than 2xx is returned, if the connection fails, or if there is no response within 10 seconds. Redirects (3xx) also count as failures and are not followed
  • After a failure, it is resent up to 5 times, at intervals of 30 seconds, 2 minutes, 10 minutes, 1 hour, and 6 hours
  • Resends have exactly the same body (including deliveryId). You can tell the same notification apart by deliveryId or X-HAKOCMS-Delivery
  • The order of arrival is not fixed. If you need order, compare occurredAt
  • If an operation succeeds, the notification is always sent. If an operation fails, it is not sent. It usually takes 1–2 seconds from the operation to sending

Even after the resends are used up, you can send the same body again by clicking [もう一度送る](Send again) in [送信履歴](Delivery history) in the admin. Delivery history is kept for 30 days.

Event Name on screen When
entry.published [エントリーの公開・公開中の更新](Entry published or published entry updated) Published. A published entry was published again
entry.draft_saved [下書きの保存](Draft saved) A draft was saved (including creation)
entry.unpublished [公開終了](Unpublished) Unpublished
entry.deleted [エントリーの削除](Entry deleted) Deleted
entry.schedule_failed [予約公開の失敗](Scheduled publishing failed) Scheduled publishing could not be done (a required field is empty, and so on)
media.uploaded [メディアの追加](Media added) Media was uploaded
media.deleted [メディアの削除](Media deleted) Media was deleted
ping [テスト](Test) [テストの送信](Send test) was clicked
  • Webhooks are sent both for operations in the admin and for writes with an API key. They are not sent when a draft is discarded
  • When scheduled publishing or unpublishing runs, entry.published and entry.unpublished are sent with actor set to { "type": "system" }
  • Media events are not sent to a webhook whose [対象のコンテンツタイプ](Target content types) is narrowed to one
{
"event": "entry.published",
"deliveryId": "d1e2f3a4b5c6",
"occurredAt": "2026-10-09T03:00:00.000Z",
"space": "blog",
"contentType": "articles",
"id": "hello",
"actor": { "type": "user", "id": "u1" },
"entry": {
"status": "published",
"published": {
"sys": { "id": "hello", "contentType": "articles" },
"title": "こんにちは(改)"
},
"draft": null
},
"previous": {
"status": "published_with_draft",
"published": {
"sys": { "id": "hello", "contentType": "articles" },
"title": "こんにちは"
},
"draft": {
"sys": { "id": "hello", "contentType": "articles" },
"title": "こんにちは(改)"
}
}
}

Part of sys is omitted in the example. In practice, it contains the same sys keys as a Content API entry.

Key Contents
event The event name
deliveryId The delivery ID. The same as X-HAKOCMS-Delivery
occurredAt When the operation happened
space The space slug
contentType The content type ID
id The entry ID
actor Who performed the operation. { "type": "user", "id" } (a person), { "type": "apiKey", "id" } (an API key), { "type": "system" } (scheduled)
entry The state after the operation. null for a deletion
previous The state before the operation. null on creation
schedule Only for entry.schedule_failed. { "action": "publish", "scheduledAt", "error" }
truncated true only when the body exceeds 1 MB. published and draft become null, so read the entry again with the Content API

The contents of entry and previous:

Key Contents
status draft (never published), published, published_with_draft (published, with a draft), closed (unpublished)
published The published revision. The same shape as a Content API entry, with references not expanded and rich text as JSON. null if there is none
draft The draft. The same shape as published. null if there is none
{
"event": "media.uploaded",
"deliveryId": "e5f6a7b8c9d0",
"occurredAt": "2026-10-09T03:00:00.000Z",
"space": "blog",
"id": "k2m9x0a1b2c3",
"actor": { "type": "user", "id": "u1" },
"media": {
"sys": { "id": "k2m9x0a1b2c3" },
"url": "https://<media host>/media/k2m9x0a1b2c3/hero.jpg",
"fileName": "hero.jpg",
"mimeType": "image/jpeg",
"size": 482113,
"kind": "image",
"width": 1920,
"height": 1080
}
}

media is part of the shape returned by the media API. It does not include alt, tags, or dates.

{
"event": "ping",
"space": "blog",
"deliveryId": "d1e2f3a4b5c6",
"occurredAt": "2026-10-09T03:00:00.000Z",
"webhook": { "id": "w1", "name": "本番サイト" }
}
[種類](Type) Body you receive
[カスタム](Custom) The bodies on this page
[Vercel(Deploy Hook)] {}. Notifications not yet sent are combined into one
[Netlify(Build Hook)] {}. Notifications not yet sent are combined into one
[Slack(Incoming Webhook)] { "text": "..." }. A message such as “記事「こんにちは」を公開しました” (Published the article “こんにちは”) and a link to the admin

For every type, a signature is added if you set [署名のシークレット](Signing secret).