Developer guide
Publishing to your site with a webhook
When you approve an article in SEOHunt, SEOHunt sends it to an address on your site (a webhook) as a signed JSON request, and your site saves it. This works for any site you built yourself, whatever it runs on. It takes about an hour to add.
Setup
- Add an endpoint to your site that accepts
POSTrequests, such ashttps://example.com/api/seohunt. It must use HTTPS. - In SEOHunt, open Settings → Custom site, enter the address and click Connect. Copy the secret it shows into your site's environment as
SEOHUNT_WEBHOOK_SECRET. - Click Send a test. When your endpoint answers 200, approved articles get a Publish to your site button.
Requests
Each message is a POST with a JSON body and these headers:
X-SEOHunt-Event:test,update_article,revert_articleorpublish_article.X-SEOHunt-Signature:t=<unix seconds>,v1=<signature>, where the signature is the hex HMAC-SHA256 of<t>.<raw body>keyed with your secret.Authorization: Bearer <secret>, if you'd rather compare the secret directly. The signature is stronger: it also proves the body wasn't changed and the message isn't old.User-Agent: SEOHunt-Webhook/1.0
Pictures
Any <img> in the body (and hero_image) whose address isn't already on your own storage is a picture on SEOHunt's storage, for example one the owner added or replaced in the editor. For every event that carries a body (update_article, revert_article, publish_article): download each such picture, host your own copy, and rewrite its src before saving. Image services and firewalls often refuse pictures from other addresses (for example Next.js /_next/image outside images.remotePatterns), which shows readers a broken picture. Keep each alt as sent.
Events
- update_article: an approved update to an existing article. Find the post by
slugorpathand replace its fields.previousholds the version before, for your own history. The body can include pictures the owner added or replaced while editing: see Pictures below. - revert_article: the user clicked Undo, or restored an earlier version.
articleholds the whole version to put back (title, meta title, meta description and body); save it the same way as an update. SEOHunt keeps every version itself, so your site doesn't need its own history. - publish_article: a new article SEOHunt wrote. Create it at
slugorpathand answer with its live address. Images in the body (andhero_image) are public https addresses on SEOHunt's storage: download them and host your own copies. - test: sent from Settings. Answer 200; there's no article.
Payload
{
"event": "update_article",
"id": "evt_3f1c2a9e-8b0d-4c57-9e61-2f4a7c1d0b55",
"created_at": "2026-11-05T14:02:11.402Z",
"site": "example.com",
"article": {
"url": "https://example.com/blog/how-to-choose-a-crm",
"slug": "how-to-choose-a-crm",
"path": "/blog/how-to-choose-a-crm",
"title": "How to Choose a CRM in 2026",
"meta_title": "How to Choose a CRM: 7 Questions to Ask (2026)",
"meta_description": "Pick a CRM in an afternoon: the 7 questions that matter, typical prices, and the mistakes small teams make.",
"author": "Jane Doe",
"content_html": "<p>Most small teams need three things from a CRM…</p><h2>1. Who will use it?</h2><p>…</p>",
"content_markdown": "Most small teams need three things from a CRM…\n\n## 1. Who will use it?\n\n…"
},
"previous": {
"title": "How to Choose a CRM",
"content_html": "<p>The version on your site before this update…</p>"
},
"changes": [
{
"type": "replace",
"before_html": "<p>Most CRMs cost $20 to $40 per user.</p>",
"before_text": "Most CRMs cost $20 to $40 per user.",
"after_html": "<p>Most CRMs cost $15 to $50 per user a month in 2026.</p>"
},
{
"type": "insert",
"after_html": "<h2>2. Which tools must it connect to?</h2><p>…</p>",
"anchor": "after",
"anchor_html": "<p>Write down who will use it every day.</p>",
"anchor_text": "Write down who will use it every day."
},
{ "type": "delete", "before_html": "<p>An outdated tip.</p>", "before_text": "An outdated tip." }
]
}| article field | What it is |
|---|---|
url | The article's full address on your site. |
slug | The last part of the address. Use it, or path, to find the post. |
path | The address without the domain, for example /blog/how-to-choose-a-crm. |
title | The headline (H1). Missing when it didn't change. |
meta_title | The title for search results, up to about 60 characters. |
meta_description | The description for search results, about 150 characters. |
author | The author's name, when the article has one. |
content_html | The full article body as HTML: headings, paragraphs, lists, links, tables. No <html>, <head> or <h1>. |
content_markdown | The same body as Markdown, for sites that store posts that way. |
hero_image | The post's main image (cover), {url, alt}. New articles: the picture SEOHunt made, which is also the first image in the body, so you can ignore it or use it as the cover. Updates and reverts: present only when the main image changed (the owner replaced it, or a revert puts the earlier one back): download it, host your own copy and make it the post's cover. Missing means leave the cover as it is. |
Fields can be missing when they don't apply. Leave anything missing as it is on your site.
Keeping your own components: apply the changes
Replacing the whole body with content_html is simplest, and right for plain articles. If your articles contain components of your own (a product card, a sign-up box, an embed), apply changes instead: the blocks this update changed, in order. Everything else in your article stays exactly as it is. revert_article sends the same list the other way.
| type | What to do |
|---|---|
replace | Swap the block whose text is before_text for after_html (one or more blocks). |
delete | Remove the block whose text is before_text. |
insert | Put after_html after (anchor "after") or before (anchor "before") the block whose text is anchor_text. That block doesn't change in this update. "start" means the top of the article. |
// Apply the changes to the stored body instead of replacing it, so your own
// components inside the article stay. Match blocks by their text: your stored HTML
// may differ in attributes or whitespace from what SEOHunt read on the live page.
import { parse } from "node-html-parser"; // or any HTML parser
const textOf = (el) => el.text.replace(/\s+/g, " ").trim();
function applyChanges(storedHtml, changes) {
const root = parse(storedHtml);
const blocks = () => root.querySelectorAll("p, h1, h2, h3, h4, h5, h6, ul, ol, table, blockquote, figure, pre");
const find = (text) => blocks().find((b) => textOf(b) === text);
for (const c of changes) {
const target = find(c.type === "insert" ? c.anchor_text : c.before_text);
if (!target && c.type !== "insert") return null; // can't place it: fall back to content_html
if (c.type === "replace") target.replaceWith(c.after_html);
else if (c.type === "delete") target.remove();
else if (c.anchor === "after" && target) target.insertAdjacentHTML("afterend", c.after_html);
else if (c.anchor === "before" && target) target.insertAdjacentHTML("beforebegin", c.after_html);
else root.insertAdjacentHTML("afterbegin", c.after_html);
}
return root.toString();
}If a block can't be found (someone edited the article since), fall back to content_html, or answer 409 with a reason so the user sees it in SEOHunt.
Example: Next.js
// app/api/seohunt/route.ts (Next.js App Router). Adapt the database calls to your own.
import { createHmac, timingSafeEqual } from "node:crypto";
const SECRET = process.env.SEOHUNT_WEBHOOK_SECRET!;
// X-SEOHunt-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">
function verified(header: string | null, body: string) {
const parts = Object.fromEntries((header ?? "").split(",").map((p) => p.split("=", 2)));
const t = Number(parts.t);
if (!t || Math.abs(Date.now() / 1000 - t) > 300) return false; // older than 5 minutes
const expected = Buffer.from(createHmac("sha256", SECRET).update(`${t}.${body}`).digest("hex"), "hex");
const given = Buffer.from(parts.v1 ?? "", "hex");
return given.length === expected.length && timingSafeEqual(given, expected);
}
export async function POST(request: Request) {
const body = await request.text(); // the raw body: verify before parsing
if (!verified(request.headers.get("x-seohunt-signature"), body)) {
return Response.json({ error: "bad signature" }, { status: 401 });
}
const { event, article } = JSON.parse(body);
if (event === "test") return Response.json({ ok: true });
if (event === "update_article" || event === "revert_article") {
const post = await db.posts.findBySlug(article.slug); // or by article.path
if (!post) return Response.json({ error: "no post with that slug" }, { status: 404 });
await db.posts.update(post.id, {
...(article.title && { title: article.title }),
...(article.meta_title && { seoTitle: article.meta_title }),
...(article.meta_description && { seoDescription: article.meta_description }),
body: article.content_html, // or article.content_markdown
updatedAt: new Date(),
});
return Response.json({ url: article.url });
}
if (event === "publish_article") {
const post = await db.posts.create({
slug: article.slug,
title: article.title,
seoTitle: article.meta_title,
seoDescription: article.meta_description,
body: article.content_html,
});
return Response.json({ url: "https://example.com/blog/" + post.slug });
}
return Response.json({ error: "unknown event" }, { status: 400 });
}In Express or another framework, read the raw request body (for example with express.raw({ type: "application/json" })) so the signature matches before you parse it.
Responses and retries
- Answer 2xx when the article is saved, ideally with
{"url": "<live address>"}, so SEOHunt links to it. - Answer 4xx with a short reason when you won't save it (for example, no post with that slug). SEOHunt shows the reason and doesn't retry.
- On a network error, a timeout (20 seconds) or a 5xx or 429, SEOHunt tries twice more, after 2 and 6 seconds.
- Redirects aren't followed: use the final address.
Articles API (optional, recommended)
Without it, SEOHunt reads each article from its live page, which loses things: your own classes and components, tables, call-to-action boxes, original image addresses (for example Next.js /_next/image?url= links) and the end of very long articles. With it, SEOHunt reads every article exactly as your site stores it, starts each update from that copy, and can import all your articles at once (Settings → Custom site → Import articles). Two GET endpoints under your webhook address:
GET {webhook address}/articles?cursor=<opaque>&limit=20
{
"items": [
{ "slug": "how-to-choose-a-crm", "url": "https://example.com/blog/how-to-choose-a-crm" }
],
"next_cursor": "eyJvZmZzZXQiOjIwfQ" // null on the last page
}GET {webhook address}/articles/how-to-choose-a-crm
{
"article": {
"url": "https://example.com/blog/how-to-choose-a-crm",
"slug": "how-to-choose-a-crm",
"path": "/blog/how-to-choose-a-crm",
"title": "How to Choose a CRM",
"meta_title": "How to Choose a CRM: 7 Questions to Ask",
"meta_description": "Pick a CRM in an afternoon…",
"author": "Jane Doe",
"content_html": "<p>Most small teams need three things from a CRM…</p>",
"content_markdown": null,
"hero_image": { "url": "https://example.com/images/crm.webp", "alt": "A sales pipeline board" },
"published_at": "2025-03-01T09:00:00Z"
}
}- The list returns published articles only.
cursoris any string you choose (an offset, an id); SEOHunt sends back thenext_cursoryou gave until it'snull.limitis 1 to 100, 50 if missing. SEOHunt asks for 20 at a time and fetches a few articles at once. published_atis an ISO 8601 date.- Missing fields are
null. An unknown slug answers404. - Check the same secret as on webhook messages:
Authorization: Bearer <secret>, andX-SEOHunt-Signature: t=<unix seconds>,v1=<signature>, where the signature is the hex HMAC-SHA256 of<t>.GET <path-with-query>keyed with your secret.path-with-queryis the path plus the query string exactly as requested, for example/api/seohunt/articles?limit=20. Reject requests older than 5 minutes. - Redirects to another host aren't followed. If the endpoints are missing (404, or not JSON), SEOHunt simply reads the live pages as before.
// Checking a GET from SEOHunt (Node). pathWithQuery = the path and query exactly as requested,
// for example new URL(request.url).pathname + new URL(request.url).search
function verifiedGet(header, pathWithQuery) {
const parts = Object.fromEntries((header ?? "").split(",").map((p) => p.split("=", 2)));
const t = Number(parts.t);
if (!t || Math.abs(Date.now() / 1000 - t) > 300) return false; // older than 5 minutes
const expected = Buffer.from(createHmac("sha256", SECRET).update(`${t}.GET ${pathWithQuery}`).digest("hex"), "hex");
const given = Buffer.from(parts.v1 ?? "", "hex");
return given.length === expected.length && timingSafeEqual(given, expected);
}Firewalls
If your site is behind Cloudflare or a similar firewall, make sure it lets the webhook through: for example, a rule that skips bot checks for your webhook's path, or for the user agent SEOHunt-Webhook. The signature check keeps the endpoint safe.
Using an AI coding tool
Give Claude Code, Cursor or a similar tool in your site's project the link to this page and your webhook address, and ask it to add the endpoint.