Webhooks
Webhooks tell your server when something happens: a post publishes or fails, an account needs reconnecting, a download is ready, a comment arrives. Every delivery is signed, retried when your server is down, and kept in a delivery history.
Add an endpoint
POST /v1/webhooks registers a URL for the events you choose. It needs the webhooks scope.
curl -X POST "https://postkea.com/api/v1/webhooks" \
-H "Authorization: Bearer $POSTKEA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://yourapp.com/webhooks/postkea",
"events": [
"post.published",
"post.partial",
"post.failed",
"job.completed"
],
"description": "Production"
}'const res = await fetch("https://postkea.com/api/v1/webhooks", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.POSTKEA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://yourapp.com/webhooks/postkea",
events: ["post.published", "post.partial", "post.failed", "job.completed"],
description: "Production",
}),
});
const { data: endpoint } = await res.json();
console.log(endpoint);import os, requests
r = requests.post(
"https://postkea.com/api/v1/webhooks",
headers={"Authorization": f"Bearer {os.environ['POSTKEA_API_KEY']}"},
json={
"url": "https://yourapp.com/webhooks/postkea",
"events": ["post.published", "post.partial", "post.failed", "job.completed"],
"description": "Production",
},
)
endpoint = r.json()["data"]
print(endpoint)The response includes the signing secret (whsec_...) in full. This is the only time it is shown; later reads show only its first characters.
Events
GET /v1/webhooks/events returns this list.
Payload and headers
Each delivery is a POST with a JSON body of id, type, createdAt and data, and these headers:
A post.partial event
{
"id": "evt_3kX9q2LmV0",
"type": "post.partial",
"createdAt": "2026-11-03T08:00:04.512Z",
"data": {
"post": {
"id": "post_8f2k1x9q0m3v7n4b2c6d",
"status": "partial",
"platforms": [
{
"accountId": "acc_x_8f2k",
"platform": "x",
"status": "published",
"platformPostUrl": "https://x.com/studiolumen/status/1849"
},
{
"accountId": "acc_ig_5t1p",
"platform": "instagram",
"status": "failed",
"error": "Instagram: the video is longer than 15 minutes",
"errorCode": "video_too_long"
}
]
}
}
}Verify signatures
Compute the HMAC-SHA256 of the timestamp header, a dot, and the raw request body, using your signing secret, and compare it with the signature header in constant time. Reject requests whose timestamp is more than a few minutes old to stop replays.
import crypto from "node:crypto";
import express from "express";
const app = express();
const SECRET = process.env.POSTKEA_WEBHOOK_SECRET; // whsec_...
// Keep the raw body: the signature is computed over the exact bytes sent.
app.post("/webhooks/postkea", express.raw({ type: "application/json" }), (req, res) => {
const timestamp = req.header("X-Postkea-Timestamp");
const signature = req.header("X-Postkea-Signature") ?? "";
const body = req.body.toString("utf8");
const expected = "sha256=" + crypto.createHmac("sha256", SECRET).update(`${timestamp}.${body}`).digest("hex");
const valid =
signature.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
const fresh = Math.abs(Date.now() / 1000 - Number(timestamp)) < 300;
if (!valid || !fresh) return res.status(401).end();
const event = JSON.parse(body);
if (event.type === "post.failed") {
// event.data.post has every platform's error
}
res.status(200).end(); // answer fast, do slow work in the background
});
app.listen(3000);import hashlib, hmac, json, os, time
from flask import Flask, request, abort
app = Flask(__name__)
SECRET = os.environ["POSTKEA_WEBHOOK_SECRET"].encode() # whsec_...
@app.post("/webhooks/postkea")
def postkea_webhook():
timestamp = request.headers.get("X-Postkea-Timestamp", "")
signature = request.headers.get("X-Postkea-Signature", "")
body = request.get_data(as_text=True) # the raw body, not re-serialized JSON
expected = "sha256=" + hmac.new(SECRET, f"{timestamp}.{body}".encode(), hashlib.sha256).hexdigest()
if not hmac.compare_digest(signature, expected) or abs(time.time() - int(timestamp or 0)) > 300:
abort(401)
event = json.loads(body)
if event["type"] == "job.completed":
print(event["data"]["job"]["result"])
return "", 200Verify against the raw body exactly as received. Parsing the JSON and serializing it again changes the bytes and the signature will not match.
Responses and retries
Answer with any 2xx status within 10 seconds. Anything else, or no answer in time, counts as a failure.
- Failed deliveries are retried after 1 minute, 5 minutes, 30 minutes and 2 hours, so each event is tried up to 5 times.
- Deliveries can arrive more than once and out of order. Deduplicate with the event id and use
createdAtor the post's current state to order them. - An endpoint that fails 50 times in a row is paused. Fix it, then turn it back on with
active: true; that also resets its failure count.
Test, inspect and redeliver
POST /v1/webhooks/testsends awebhook.testevent to a saved endpoint (webhookId) or to anyurlbefore you save it, and reports the status, body and time of the answer. Tests to an unsaved URL are signed with the secretwhsec_test.GET /v1/webhooks/{id}/deliverieslists deliveries with their status (pending,succeeded,retrying,failed,cancelled), attempts, response status and body.POST /v1/webhooks/deliveries/{id}/redeliversends a delivery again.POST /v1/webhooks/{id}/secretissues a new signing secret. Update your server first, the old secret stops working at once.PATCHchanges the URL, events, profile oractive, andDELETEremoves the endpoint.
curl -X POST "https://postkea.com/api/v1/webhooks/test" \
-H "Authorization: Bearer $POSTKEA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://yourapp.com/webhooks/postkea"
}'const res = await fetch("https://postkea.com/api/v1/webhooks/test", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.POSTKEA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://yourapp.com/webhooks/postkea",
}),
});
const { data: test } = await res.json();
console.log(test);import os, requests
r = requests.post(
"https://postkea.com/api/v1/webhooks/test",
headers={"Authorization": f"Bearer {os.environ['POSTKEA_API_KEY']}"},
json={
"url": "https://yourapp.com/webhooks/postkea",
},
)
test = r.json()["data"]
print(test)