Connect a webhook
For AI agents: the docs index is at /llms.txt, and every page is also served as markdown at its URL plus .md.
In this guide
A webhook connection sends each approved article to an https address of yours. You write the small receiver that stores it. This guide takes you from the secret to a working check in Node or Python.
What you need
- A public https address that accepts a
POST, on the standard port. Private addresses, plain http and redirects are refused. - A signing secret of at least 16 characters, for example the output of
openssl rand -hex 32. Keep it in your receiver's settings, not in your code. - Somewhere to store a post and a way to remember which idempotency keys you have already handled.
Connect the site
- Add the site with the webhook platform, then send the connection with the address and the secret:
POST /v1/sites/{siteId}/connectionwith{ "credentials": { "url": "https://...", "signing_secret": "..." } }. - BlogAutoPost sends one signed
webhook.testevent to the address and waits for a 2xx. The connection is saved only if that works. - Approve an article and publish it. Your receiver gets an
article.publishevent with the whole article.
To change the secret or the address, connect again with the new values. The old ones are replaced.
What your receiver gets
Three headers carry the proof and the key. The body is JSON. The full list of fields is on the webhook integration page.
| Header | Value |
|---|---|
X-BlogAutoPost-Timestamp | Unix seconds when this try was signed. |
X-BlogAutoPost-Signature | v1= followed by the lowercase hex HMAC-SHA256 of <timestamp>.<raw body> under your secret. |
Idempotency-Key | The article id. The same value on every try for the same article. |
Check the signature
Compute the signature over the raw bytes of the body, exactly as they arrived. Parse the JSON only after the check passes, because a parsed and re-written body will not match. Compare in constant time, and refuse a timestamp more than five minutes from your clock.
Node
import { createHmac, timingSafeEqual } from 'node:crypto';
import { createServer } from 'node:http';
const SECRET = process.env.BLOGAUTOPOST_SIGNING_SECRET;
const TOLERANCE_SECONDS = 300;
function isValid(rawBody, headers) {
const timestamp = String(headers['x-blogautopost-timestamp'] ?? '');
const given = String(headers['x-blogautopost-signature'] ?? '');
if (!/^\d+$/.test(timestamp)) return false;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > TOLERANCE_SECONDS) return false;
const expected = 'v1=' + createHmac('sha256', SECRET).update(timestamp + '.').update(rawBody).digest('hex');
const a = Buffer.from(given);
const b = Buffer.from(expected);
return a.length === b.length && timingSafeEqual(a, b);
}
const published = new Map(); // article id (the idempotency key) -> public URL. Use your database.
createServer(async (req, res) => {
const chunks = [];
for await (const chunk of req) chunks.push(chunk);
const raw = Buffer.concat(chunks);
if (!isValid(raw, req.headers)) return res.writeHead(401).end('bad signature');
const body = JSON.parse(raw.toString('utf8'));
if (body.event === 'webhook.test') return res.writeHead(200).end('{}');
const key = req.headers['idempotency-key'];
// savePost is yours: it creates the post, or replaces the one stored under this article id, and returns the public URL.
// The article may have been edited since an earlier try whose answer was lost, so the latest text is the one to keep.
published.set(key, await savePost(body.article));
res.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ url: published.get(key) }));
}).listen(3000);Python
import hashlib
import hmac
import json
import os
import time
from http.server import BaseHTTPRequestHandler, HTTPServer
SECRET = os.environ["BLOGAUTOPOST_SIGNING_SECRET"].encode()
TOLERANCE_SECONDS = 300
published = {} # article id (the idempotency key) -> public URL. Use your database.
def is_valid(raw_body: bytes, headers) -> bool:
timestamp = headers.get("X-BlogAutoPost-Timestamp", "")
given = headers.get("X-BlogAutoPost-Signature", "")
if not timestamp.isdigit() or abs(time.time() - int(timestamp)) > TOLERANCE_SECONDS:
return False
expected = "v1=" + hmac.new(SECRET, timestamp.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(given, expected)
class Hook(BaseHTTPRequestHandler):
def reply(self, status: int, payload: bytes = b"{}") -> None:
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.end_headers()
self.wfile.write(payload)
def do_POST(self):
raw = self.rfile.read(int(self.headers.get("Content-Length", 0)))
if not is_valid(raw, self.headers):
return self.reply(401, b'{"error":"bad signature"}')
body = json.loads(raw)
if body["event"] == "webhook.test":
return self.reply(200)
key = self.headers["Idempotency-Key"]
# save_post is yours: it creates the post, or replaces the one stored under this article id, and returns the public URL.
# The article may have been edited since an earlier try whose answer was lost, so the latest text is the one to keep.
published[key] = save_post(body["article"])
self.reply(200, json.dumps({"url": published[key]}).encode())
HTTPServer(("", 3000), Hook).serve_forever()Answer with the address of the post
Reply with any 2xx once the post is stored. If the body is JSON with a url, BlogAutoPost shows that address as the published link and tells search engines about it. An id is kept as the post id on your side. A bare 200 also works; the post is then marked published with no link.
Be safe to call twice
Store each post under its Idempotency-Key, which is the article id. When the same key arrives again, replace the stored post with the one in the new body and answer with its address instead of creating a second post. A repeat happens when your answer is lost on the way back, and BlogAutoPost cannot tell that from a failure. The customer may have edited the article before the next try, so the newest body is the one to keep.
Failures and what to do
| Code | Meaning | What to do |
|---|---|---|
webhook_rejected | Your receiver answered 4xx. The message gives the status and the first words of the reply. | Fix what the reply names, then publish again. A 401 usually means the receiver is using a different secret. |
webhook_redirect | The address answered with a redirect. | Save the final address instead. |
blocked_target | The address is private or on a port other than 443. A plain http address never gets this far: saving the connection refuses it. | Use a public https address on the standard port. |
provider_unavailable | Your receiver answered 5xx or did not answer, three times. | Fix the receiver and publish again. The same key is sent. |
A 5xx, 408, 425, 429 or a timeout is tried again with waits of one and four seconds. Any other 4xx stops at once. See errors for the full list.
Next guide
Approvals and scheduling
How posts reach your site: the approval queue, opt-in auto-publish with a daily cap, plan quotas and the scheduler rules that keep volume low.
Read the guide