Guide8 min read
Connect a website you coded yourself
Publish articles from Postwme to your own Next.js, Express or PHP site. Give Postwme one address on your site, keep a secret, and answer each article with its link.
You coded your website yourself, in Next.js, Express, PHP or anything else, and you want the articles you write in Postwme to land on it. Postwme does this with webhooks. Each article is sent to an address on your site, signed with a secret only your site knows. Your site saves the post and answers with its link.
This guide covers the setup in Postwme, the code your site needs, and the five rules that keep your site safe and free of duplicate posts.
How it works
- You give Postwme an address on your site, for example
https://example.com/api/postwme. - Postwme gives you a secret. Your site keeps it and uses it to check that each delivery really comes from Postwme.
- When you publish an article, Postwme sends it to that address. Your site saves it and answers with
the post's
idandurl. - Later, Postwme can send the same post again with changes, or ask your site to delete it.
A custom website takes articles only: a title, a body, images, categories, tags and SEO fields. Postwme only sends to your site; it never reads anything from it.
1. Connect the site in Postwme
- In Postwme, open Connect a channel and choose Website, then Custom website.
- In Address that receives the articles, type the HTTPS address on your site that will take the
deliveries, e.g.
https://example.com/api/postwme. Postwme keeps the path and query as you type them. - Give it a Name, e.g.
My blog, and connect. - Postwme shows the secret, which starts with
whsec_. It is shown once: press Copy and put it in your site's configuration as the environment variablePOSTWME_WEBHOOK_SECRET.
Don't press Send test yet. Your site needs the code below first.
Lost the secret, or think it leaked? Connect the same address again, or press Reconnect on the login. You get a new secret, and the old one stops working.
2. Add the receiver to your site
Postwme sends a POST with a JSON body and three signature headers:
POST https://example.com/api/postwme
content-type: application/json
user-agent: Postwme/1.0 (+https://postwme.com)
webhook-id: msg_…
webhook-timestamp: 1763712000
webhook-signature: v1,<base64>
{"type": "article.published", "timestamp": "2026-11-21T08:00:00.000Z", "data": { … }}
The signature follows the Standard Webhooks spec, so you don't have
to write the check yourself: the standardwebhooks package on npm and PyPI does it in one call. It
also refuses a delivery whose timestamp is more than five minutes off.
Here is a complete receiver for Express (Node 18 or later). Install it with
npm install express standardwebhooks@1.0.0:
import express from "express";
import { Webhook } from "standardwebhooks";
// ---- YOUR SITE: swap these for your database and your storage ----
const answers = new Map(); // webhook-id → the answer you sent (a table in your database)
const posts = new Map(); // your posts
async function copyImage(url) {
const res = await fetch(url);
if (!res.ok) throw new Error(`image ${res.status}`);
return url; // store the bytes where your site serves files and return YOUR url
}
const SITE = process.env.SITE_URL ?? "https://example.com";
// -------------------------------------------------------------------
const wh = new Webhook(process.env.POSTWME_WEBHOOK_SECRET);
const POSTWME_LINK = /https?:\/\/[^\s"'()<>]+\/api\/calendar\/public\/article\/[^\s"'()<>]+/g;
// Copy every Postwme image into your own storage and point the post at the copies.
async function withCopies(a) {
const links = new Set([...(a.html.match(POSTWME_LINK) ?? []), ...(a.markdown.match(POSTWME_LINK) ?? [])]);
if (a.featuredImage) links.add(a.featuredImage.url);
for (const g of a.gallery) links.add(g.url);
const copies = new Map();
for (const link of links) copies.set(link, await copyImage(link));
const swap = (s) => s.replace(POSTWME_LINK, (l) => copies.get(l) ?? l);
return {
...a,
html: swap(a.html),
markdown: swap(a.markdown),
featuredImage: a.featuredImage ? { url: copies.get(a.featuredImage.url) ?? a.featuredImage.url } : null,
gallery: a.gallery.map((g) => ({ url: copies.get(g.url) ?? g.url })),
};
}
const app = express();
// The raw body: the signature covers these exact bytes, so no JSON parser runs first.
app.post("/api/postwme", express.raw({ type: "application/json", limit: "5mb" }), async (req, res) => {
let event;
try {
event = wh.verify(req.body.toString("utf8"), req.headers);
} catch {
return res.status(401).json({ error: "Bad signature" });
}
const msgId = req.headers["webhook-id"];
if (answers.has(msgId)) return res.json(answers.get(msgId)); // same delivery again: same answer
try {
let status = 200, body;
if (event.type === "test") body = { ok: true, name: "My site" };
else if (event.type === "article.published") {
const article = await withCopies(event.data.article);
const id = article.slug || crypto.randomUUID();
posts.set(id, article);
body = { id, url: `${SITE}/blog/${id}` };
} else if (event.type === "article.updated") {
const id = event.data.remoteId;
if (!posts.has(id)) [status, body] = [404, { error: "No such post" }];
else {
posts.set(id, await withCopies(event.data.article));
body = { id, url: `${SITE}/blog/${id}` };
}
} else if (event.type === "article.deleted") {
if (posts.delete(event.data.remoteId)) body = { ok: true };
else [status, body] = [404, { error: "No such post" }];
} else [status, body] = [400, { error: `Unknown type ${event.type}` }];
if (status < 300) answers.set(msgId, body);
res.status(status).json(body);
} catch (error) {
res.status(500).json({ error: String(error) });
}
});
app.listen(process.env.PORT ?? 3000);
Replace the parts marked YOUR SITE: where a post is saved, where an image is copied to, and the table
that remembers each webhook-id. On Next.js, the same logic goes in app/api/postwme/route.ts:
read the body with await req.text() and pass it to wh.verify with the request's headers.
Plain PHP, without a library
The signature is an HMAC-SHA256 of <webhook-id>.<webhook-timestamp>.<raw body>, keyed with the bytes
of the secret (the base64 after whsec_), then base64-encoded. In PHP 8 the check takes a few lines:
<?php
$raw = file_get_contents('php://input');
$msgId = $_SERVER['HTTP_WEBHOOK_ID'] ?? '';
$timestamp = $_SERVER['HTTP_WEBHOOK_TIMESTAMP'] ?? '';
$key = base64_decode(preg_replace('/^whsec_/', '', getenv('POSTWME_WEBHOOK_SECRET') ?: ''));
$expected = base64_encode(hash_hmac('sha256', "$msgId.$timestamp.$raw", $key, true));
$ok = false;
foreach (explode(' ', $_SERVER['HTTP_WEBHOOK_SIGNATURE'] ?? '') as $one) {
[$version, $sig] = array_pad(explode(',', $one, 2), 2, '');
if ($version === 'v1' && hash_equals($expected, $sig)) $ok = true;
}
if (!$ok || !ctype_digit($timestamp) || abs(time() - (int) $timestamp) > 300) {
http_response_code(401);
exit(json_encode(['error' => 'Bad signature']));
}
$event = json_decode($raw, true);
// … then handle $event['type'] as in the Express example.
3. Press Send test
Deploy your site with the secret set, go back to Postwme and press Send test. Postwme sends a
test delivery and shows what your site answered:
- Your site answered 200: you are connected. If your answer was
{"name": "Your site"}, Postwme renames the site to match. - Anything else: Postwme shows the start of your site's answer, so you can see what went wrong. A 401 usually means the secret in your site is not the one Postwme showed, or the body was parsed before the signature was checked.
What Postwme sends
Every delivery has a type. Here is what your site should answer for each:
type |
data |
Your answer (2xx, JSON) |
|---|---|---|
test |
{pageId} |
anything; {"name": "Your site"} renames the site in Postwme |
article.published |
{id, remoteId: null, article} |
{"id": "<your post's id>", "url": "https://…/the-post"}, required |
article.updated |
{id, remoteId, article} |
{"id", "url"} if the link changed; anything else keeps the old one |
article.deleted |
{remoteId} |
anything; 404 or 410 if you have no such post (Postwme treats it as already gone) |
id is Postwme's id for the post, and remoteId is yours: the id you answered to
article.published. The article holds:
| Field | What it is |
|---|---|
title, slug, excerpt, lang |
text; slug and excerpt may be empty |
status |
publish, draft, pending or private, as chosen in Postwme; what each means on your site is up to you |
format |
standard, image, gallery or video |
html |
the body as HTML, ready to show; images as <figure><img src="…" alt="…"></figure> |
markdown |
the same body as Markdown |
featuredImage |
{url} or null |
gallery |
[{url}], in order |
categories, tags |
names, as written in Postwme |
seo |
{title, description, canonicalUrl}, each may be empty |
The five rules
- Check the signature first. Check it on the raw body, before parsing it. If it does not match, answer 401 and do nothing else.
- Answer each
webhook-idonce. Keep everywebhook-idwith the answer you gave. If the same id comes again, send the same answer back and create nothing. Postwme resends under the same id when your first answer was lost and someone pressed Retry. This rule is what keeps you from getting two copies of a post. - Copy the images before you answer. Images from your Postwme Library come as links that work for
seven days. Copy the
featuredImage, thegalleryand every such link inhtmlandmarkdowninto your own storage, and point the post at your copies. - Answer within 60 seconds, and answer 2xx only when the post is really saved. A 4xx tells Postwme
you refused it: your
error(ormessage) is shown in Postwme and nothing is sent again. A 5xx or no answer means "it may have worked": Postwme waits for a person to check your site and press Retry, which is safe thanks to rule 2. - HTTPS only, no redirects. Postwme does not follow redirects, so give the final address.
Questions
Can several people post to the same site? Yes. Each person who connects the same address gets their own secret. Your site checks the signature against each secret it holds. In Postwme, they can also share one site through Sharing.
How do I change the secret? Connect the same address again, or press Reconnect on the login. The new secret replaces the old one at once, so update your site right after.
Can I edit or remove a post after it is out? Yes. Sending a post again delivers article.updated
with your remoteId; deleting it delivers article.deleted.
Stuck? Write to support@postwme.com with what Send test showed, and we will help.