Help
Webhook recipes
Ready steps to receive Kitto articles in Zapier, Make, a Next.js app or a PHP script. Each recipe checks that the request really came from Kitto.
Signature or bearer token
Every request from Kitto is signed in the X-Kitto-Signature header. When you connect, you can also pick Bearer token: you make up a long random token, and Kitto sends it in every request as Authorization: Bearer your-token. The signature is still there, so you can check both.
- Zapier or Make: pick Bearer token. These tools can compare a header with your token, but they can't easily check a signature.
- Your own code: keep Signature (recommended). It also proves that nobody changed the article on the way and stops old requests from being sent again.
Please use at least 16 characters for the token: letters, digits and - . _ ~ + /, no spaces. Kitto keeps it encrypted and never shows it again. To change it, connect again with a new token.
Send a test first
After you connect, press Send test in Kitto. We send the event endpoint.verify with "test": true and a sample article (article.test is true and article.status is draft), then show you the answer code and the first 300 characters of the answer. In Zapier and Make the test fills in every field, so you can map them. Please don't publish the test article: skip events where test is true.
Zapier
- In Kitto, connect a webhook with Bearer token. Turning off Include image files keeps each request small; the pictures still come as links.
- In Zapier, create a Zap with the trigger Webhooks by Zapier, event Catch Raw Hook. The raw version keeps the request headers, which you need for the token. Copy the address Zapier gives you and paste it into Kitto.
- Press Send test in Kitto, then Test trigger in Zapier.
- Add a Code by Zapier step, "Run JavaScript". In Input Data, set
bodyto the raw body andauthto the Authorization header from the trigger. Paste this code:
// Code step, "Run JavaScript".
// Input Data: body = Raw Body, auth = the Authorization header from the trigger.
const TOKEN = "paste-the-same-token-you-gave-Kitto";
const event = JSON.parse(inputData.body);
const article = event.article || {};
const cover = (article.images || []).find((image) => image.role === "cover");
return {
allowed: inputData.auth === "Bearer " + TOKEN,
event: event.event,
test: event.test === true,
status: article.status || "",
title: article.title || "",
slug: article.slug || "",
html: article.html || "",
meta_description: article.meta_description || "",
cover_url: cover ? cover.url : "",
cover_alt: cover ? cover.alt : "",
};- Add a Filter step: only continue if
allowedis true,eventisarticle.published,testis false andstatusispublish. - Add the action that publishes the article, for example a new post in your blog tool, and map
title,html,slugandcover_url.
The picture links work for 7 days. Please let your action copy the file (most blog tools do this when you give them an image address), rather than putting our link into the article.
Make
- In Kitto, connect a webhook with Bearer token.
- In Make, start a scenario with Webhooks, Custom webhook. Add a webhook and, in its advanced settings, turn on Get request headers. Copy the address into Kitto.
- Press Redetermine data structure in Make, then Send test in Kitto. Make learns every field from the sample article.
- On the link after the webhook, add a filter: the
authorizationheader equalsBearer your-token,eventequalsarticle.published,testis not true, andarticle.statusequalspublish. - Add the module that publishes the article and map
article.title,article.htmlandarticle.images[].url. Make answers 200 by itself, which is all Kitto needs.
Next.js
A route handler for the App Router. It checks the bearer token if you set one, and always checks the signature.
// app/api/kitto/route.ts
import crypto from "node:crypto";
const SECRET = process.env.KITTO_WEBHOOK_SECRET!; // starts with kitto_whsec_
const BEARER = process.env.KITTO_WEBHOOK_TOKEN; // only if you picked Bearer token
const TOLERANCE_SEC = 300;
function safeEqual(a: string, b: string) {
const left = Buffer.from(a);
const right = Buffer.from(b);
return left.length === right.length && crypto.timingSafeEqual(left, right);
}
function signatureIsValid(header: string, rawBody: string) {
let t: number | null = null;
const signatures: string[] = [];
for (const part of header.split(",")) {
const [key, value] = part.trim().split("=");
if (key === "t" && /^\d+$/.test(value ?? "")) t = Number(value);
if (key === "v1" && /^[0-9a-f]{64}$/.test(value ?? "")) signatures.push(value);
}
if (t === null || signatures.length === 0) return false;
if (Math.abs(Date.now() / 1000 - t) > TOLERANCE_SEC) return false;
const expected = crypto.createHmac("sha256", SECRET).update(t + "." + rawBody, "utf8").digest("hex");
return signatures.some((sig) => safeEqual(sig, expected));
}
export async function POST(request: Request) {
// Important: read the RAW body. The signature covers the exact bytes we sent.
const rawBody = await request.text();
if (BEARER && !safeEqual(request.headers.get("authorization") ?? "", "Bearer " + BEARER)) {
return new Response(null, { status: 401 });
}
if (!signatureIsValid(request.headers.get("x-kitto-signature") ?? "", rawBody)) {
return new Response(null, { status: 401 });
}
const event = JSON.parse(rawBody);
if (event.event === "endpoint.verify") {
return Response.json({ ok: true }); // the connection check and Send test
}
// Skip a delivery you have already handled: request.headers.get("x-kitto-delivery").
// ... save event.article here (see "Save the pictures" below) ...
return Response.json({ url: "https://example.com/blog/" + event.article.slug, id: "your-own-id" });
}Kitto shows the signing secret right after the first check, so that first check can't pass the signature test yet. That's fine: save the secret in your settings, then press Check again or Send test.
PHP
One file, no libraries. The same checks as the Next.js example.
<?php
$secret = getenv('KITTO_WEBHOOK_SECRET'); // starts with kitto_whsec_
$bearer = getenv('KITTO_WEBHOOK_TOKEN'); // only if you picked Bearer token
$tolerance = 300;
// Important: read the RAW body. The signature covers the exact bytes we sent.
$rawBody = file_get_contents('php://input');
if ($bearer) {
// Some Apache setups move the header to REDIRECT_HTTP_AUTHORIZATION.
$auth = $_SERVER['HTTP_AUTHORIZATION'] ?? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ?? '';
if (!hash_equals('Bearer ' . $bearer, $auth)) {
http_response_code(401);
exit;
}
}
$header = $_SERVER['HTTP_X_KITTO_SIGNATURE'] ?? '';
$t = null;
$signatures = [];
foreach (explode(',', $header) as $part) {
$pair = explode('=', trim($part), 2);
if (count($pair) !== 2) continue;
if ($pair[0] === 't' && ctype_digit($pair[1])) $t = (int) $pair[1];
if ($pair[0] === 'v1' && preg_match('/^[0-9a-f]{64}$/', $pair[1])) $signatures[] = $pair[1];
}
if ($t === null || count($signatures) === 0 || abs(time() - $t) > $tolerance) {
http_response_code(401);
exit;
}
$expected = hash_hmac('sha256', $t . '.' . $rawBody, $secret);
$ok = false;
foreach ($signatures as $sig) {
if (hash_equals($expected, $sig)) $ok = true;
}
if (!$ok) {
http_response_code(401);
exit;
}
$event = json_decode($rawBody, true);
header('Content-Type: application/json');
if ($event['event'] === 'endpoint.verify') {
echo json_encode(['ok' => true]); // the connection check and Send test
exit;
}
// Skip a delivery you have already handled: $_SERVER['HTTP_X_KITTO_DELIVERY'].
// ... save $event['article'] here ...
echo json_encode(['url' => 'https://example.com/blog/' . $event['article']['slug'], 'id' => 'your-own-id']);Save the pictures
Each picture in article.images has a url: a private link to the file on app.kittoseo.com. It works for 7 days from the moment we send the article, then answers 404. The file itself is also in data_base64, unless you turned off Include image files (then omitted is files_off). Inline pictures appear in the html as cid:FILENAME. Please copy each file to your own storage and replace the cid reference with your own address:
// Node.js 18+: copy each picture to your own storage right away.
for (const image of event.article.images) {
const bytes = image.data_base64
? Buffer.from(image.data_base64, "base64")
: Buffer.from(await (await fetch(image.url)).arrayBuffer()); // link works for 7 days
const myUrl = await saveToMyStorage(image.filename, image.mime, bytes);
event.article.html = event.article.html.replaceAll("cid:" + image.filename, myUrl);
}Need a hand?
The full request format, all events and answer codes are in Publish with a webhook. Please write to us and we will gladly look at your first delivery with you.