On this page
Webhooks
Postsure sends a signed POST to your URL when a post is done, when it starts waiting for a retry, and when an account changes. You do not need to ask again and again.
Add a webhook
Send the URL that gets the events. It must be a public https address.
curl https://api.postsure.dev/v1/webhooks \ -H "Authorization: Bearer $POSTSURE_KEY" \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com/hooks"}'const api = "https://api.postsure.dev";const headers = { Authorization: `Bearer ${process.env.POSTSURE_KEY}`, "Content-Type": "application/json",};const webhook = await fetch(`${api}/v1/webhooks`, { method: "POST", headers, body: JSON.stringify({ url: "https://example.com/hooks" }),}).then((r) => r.json());console.log(webhook.id); // Save webhook.secret now: it is shown only once.import osimport requestsapi = "https://api.postsure.dev"headers = {"Authorization": f"Bearer {os.environ['POSTSURE_KEY']}"}webhook = requests.post(f"{api}/v1/webhooks", headers=headers, json={ "url": "https://example.com/hooks",}).json()print(webhook["id"]) # Save webhook["secret"] now: it is shown only once.Example response201
{ "id": "cmgx2c8wd0001l708h3k5n7pq", "url": "https://example.com/hooks", "events": [ "post.waiting", "post.published", "post.partially_failed", "post.failed", "post.unconfirmed", "post.delayed", "account.connected", "account.needs_reconnect", "account.active", "account.updated", "account.disabled", "account.removed" ], "enabled": true, "failure_count": 0, "previous_secret_expires_at": null, "created_at": "2026-10-18T11:00:00.000Z", "secret": "whsec_EXAMPLEonlyEXAMPLEonlyEXAMPLEonly0"}Save the secret now. It starts with whsec_, and this reply is the only time Postsure shows it. You need it to check that each event comes from Postsure. Postsure keeps it encrypted.
With no events, the webhook gets every event that exists then. To get only some, send a list, for example "events": ["post.failed"]. You can add more later with PATCH.
A URL that is not public, such as one on your own machine or a private network, gets 400 with invalid_webhook_url: "The URL must be a public address, not this machine or a private network."
Events
The type of each event says what happened. Events may come out of order, so use timestamp to know which is newest.
Post events
A post sends an event when it starts to wait, when it has waited more than 15 minutes for its turn, and when it is done.
| Event | When it is sent |
|---|---|
post.waiting | A try failed, for example on a rate limit or a network error, or the post is waiting its turn. It goes at retry_at. Sent once per post, and once per retry you ask for. |
post.published | The post is live on every account. |
post.partially_failed | The post is live on some accounts and not on others. |
post.failed | The post failed on every account. Each target says why, in error_reason. |
post.unconfirmed | The network may have posted it, but its answer was lost. Postsure does not send it again by itself. Check the account, then retry it or confirm it. |
post.delayed | One of the post's accounts has waited more than 15 minutes in all for its turn. The post is still waiting, and Postsure still sends it by itself. Sent once per post, and once more after a retry you ask for if it waits that long again. See When a post waits its turn. |
- A post with an
unconfirmedaccount can change again when the network's late answer gives the sure result. You then getpost.published,post.partially_failedorpost.failed. Each event type is sent at most once per post, until you retry or confirm an account. On Bluesky, a late success changes nothing. - After a retry of an account you ask for, or a
confirm-posted, the post sends its events again as at the end of any send: each type at most once for each retry or confirm. - A draft sends no event until you publish it, and a scheduled post none until its
publish_at. Then they send the same events as any post. - A cancelled post sends no event. There is no
post.cancelled: you made the change. - A webhook gets
post.delayedonly when itseventslist has it. A webhook added before this event came out does not get it until you add it to itseventswithPATCH. - With
post.delayed, you also get one "Post delayed" email. You can turn it off in your notification settings.
Receipts and retries explains each status and when Postsure tries again.
Account events
An account sends an event when it connects, stops working, works again, or changes.
| Event | When it is sent |
|---|---|
account.connected | A connect finished, for a new account or one connected again. |
account.needs_reconnect | The account stopped working and cannot post. status_reason says why and how to fix it. Sent once per change. |
account.active | An account that needed a reconnect works again, with no new connect. |
account.updated | The account's chat id, chat type, title or @name changed, and its status did not. |
account.disabled | Postsure turned the account off. It cannot post, and status_reason names the account to post to instead. |
account.removed | You removed the account. Its status is removed, and no event about it comes after this one. |
Connect accounts says how to connect an account again.
The event body
A post event has the post's status and every target, with its parts and its status_text, a status in plain words you can show to your user. It does not have the post's text or the attempts. The examples on this page are trimmed: the API reference has every field. This post failed on X:
Example body
{ "type": "post.failed", "timestamp": "2026-10-18T12:00:01.904Z", "data": { "id": "cmgwb1n6e000bl808v5j0k8ry", "status": "failed", "retry_at": null, "created_at": "2026-10-18T12:00:00.000Z", "updated_at": "2026-10-18T12:00:01.904Z", "targets": [ { "id": "cmgwb1n6f000cl808a2m4s9tw", "account_id": "cmgw7k2xq0003l808x9f2h1ab", "status": "failed", "url": null, "error_category": "content_policy", "error_reason": "X does not allow posting the same text twice.", "retry_at": null, "account": { "network": "x", "username": "postsure_demo" }, "status_text": "X does not allow posting the same text twice." } ] }}An account event has the whole account. Find it by its id, which never changes, and keep the newest by timestamp. Here a Telegram bot was removed from its channel:
Example body
{ "type": "account.needs_reconnect", "timestamp": "2026-10-24T13:05:01.000Z", "data": { "id": "cmh2c4v8n0009l808k6t1w5pz", "network": "telegram", "username": "postsure_news", "display_name": "Postsure News", "status": "needs_reconnect", "status_reason": "Add @PostsureBot back to Postsure News as an admin.", "checked_at": "2026-10-24T13:05:01.000Z", "chat_type": "channel" }}Headers
Every event comes with three headers. They follow Standard Webhooks.
webhook-id- The delivery's id. It stays the same on every try, and when you send the delivery again.
webhook-timestamp- When this try was signed, in seconds since 1 January 1970 (Unix time).
webhook-signaturev1,and the signature. For 24 hours after you rotate the secret, it holds two signatures, split by a space.
The body is JSON (Content-Type: application/json), and the User-Agent is Postsure-Webhooks/1.0.
Verify the signature
Check every event before you trust it. Anyone can send a POST to your URL, but only Postsure has your secret.
- Take the secret without
whsec_, and decode it from base64. That is the key. - Join three things with dots:
webhook-id,webhook-timestampand the raw body. That is the signed text. - Make an HMAC-SHA256 of the signed text with the key, and encode it in base64.
- It must match one of the signatures in
webhook-signature, afterv1,. Compare them in constant time. - Turn down a
webhook-timestampmore than 5 minutes away from your clock, so an old event cannot be sent to you again.
Use the raw body: the text exactly as it came, before you parse the JSON. JSON that is parsed and written again can change, and then the signature does not match. These functions use only the standard library:
import { createHmac, timingSafeEqual } from "node:crypto";// secret: the whsec_... secret of your webhook.// headers: the request's headers, with lower-case names.// body: the raw request body, as a string, before you parse it.export function verifyWebhook(secret, headers, body) { const id = headers["webhook-id"]; const timestamp = headers["webhook-timestamp"]; const signatures = headers["webhook-signature"]; if (!id || !timestamp || !signatures) return false; // Turn down an event signed more than 5 minutes ago, or ahead. const seconds = Number(timestamp); const age = Math.abs(Date.now() / 1000 - seconds); if (!Number.isInteger(seconds) || age > 5 * 60) return false; const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64"); const signed = `${id}.${timestamp}.${body}`; const expected = createHmac("sha256", key).update(signed).digest(); // One signature, or two after you rotate the secret: "v1,<base64> v1,<base64>". return signatures.split(" ").some((item) => { const [version, signature] = item.split(","); if (version !== "v1" || !signature) return false; const given = Buffer.from(signature, "base64"); return given.length === expected.length && timingSafeEqual(given, expected); });}import base64import hashlibimport hmacimport timedef verify_webhook(secret: str, headers, body: bytes) -> bool: """secret: the whsec_... secret of your webhook. headers: the request's headers, with lower-case names (a dict, or your framework's headers). body: the raw request body, as bytes, before you parse it.""" msg_id = headers.get("webhook-id") timestamp = headers.get("webhook-timestamp") signatures = headers.get("webhook-signature") if not msg_id or not timestamp or not signatures: return False # Turn down an event signed more than 5 minutes ago, or ahead. try: if abs(time.time() - int(timestamp)) > 5 * 60: return False except ValueError: return False key = base64.b64decode(secret.removeprefix("whsec_")) signed = f"{msg_id}.{timestamp}.".encode() + body digest = hmac.new(key, signed, hashlib.sha256).digest() expected = base64.b64encode(digest).decode() # One signature, or two after you rotate the secret: "v1,<base64> v1,<base64>". for item in signatures.split(" "): version, _, signature = item.partition(",") if version == "v1" and hmac.compare_digest(signature, expected): return True return FalseAnswer fast
Answer with any 2xx status within 10 seconds. Anything else counts as a failed try: another status, no answer in time, or a redirect, which Postsure does not follow. So check the signature, answer, and do the slow work after.
import { createServer } from "node:http";// verifyWebhook is the function above, in the same file.const secret = process.env.POSTSURE_WEBHOOK_SECRET;createServer(async (req, res) => { const chunks = []; for await (const chunk of req) chunks.push(chunk); const body = Buffer.concat(chunks).toString("utf8"); if (!verifyWebhook(secret, req.headers, body)) { res.writeHead(401).end("invalid signature"); return; } res.writeHead(200).end("ok"); // Answer first. // Then do the work. Skip a webhook-id you already handled. const event = JSON.parse(body); console.log(req.headers["webhook-id"], event.type, event.data.id);}).listen(3000);import jsonimport osfrom http.server import BaseHTTPRequestHandler, HTTPServer# verify_webhook is the function above, in the same file.SECRET = os.environ["POSTSURE_WEBHOOK_SECRET"]class Webhook(BaseHTTPRequestHandler): def do_POST(self): body = self.rfile.read(int(self.headers["Content-Length"])) if not verify_webhook(SECRET, self.headers, body): self.send_response(401) self.end_headers() self.wfile.write(b"invalid signature") return self.send_response(200) # Answer first. self.end_headers() self.wfile.write(b"ok") # Then do the work. Skip a webhook-id you already handled. event = json.loads(body) print(self.headers["webhook-id"], event["type"], event["data"]["id"])HTTPServer(("", 3000), Webhook).serve_forever()The same event can come more than once, for example when your answer came too late. It has the same webhook-id each time, so you can skip one you already handled.
Retries
When a try fails, Postsure tries again. A delivery gets up to 8 tries, over about 9 hours:
| Try | Wait before it |
|---|---|
| 1 | At once |
| 2 | 30 seconds |
| 3 | 1.5 minutes |
| 4 | 4.5 minutes |
| 5 | 13.5 minutes |
| 6 | 40 minutes |
| 7 | 2 hours |
| 8 | 6 hours |
After 5 deliveries in a row fail, each one after all its tries, Postsure pauses the webhook: enabled becomes false. A delivery that works sets failure_count back to 0. See Pause and turn on again.
List deliveries
Every event sent to a webhook is a delivery. The list is newest first, with the body that was sent and your endpoint's last answer.
curl https://api.postsure.dev/v1/webhooks/<webhook id>/deliveries \ -H "Authorization: Bearer $POSTSURE_KEY"Example response200
{ "data": [ { "id": "cmgx9f3kd0004l708r2v6b8nc", "event_type": "post.failed", "post_id": "cmgwb1n6e000bl808v5j0k8ry", "account_id": null, "attempts": 8, "response_status": 503, "response_body": "<html><body><h1>503 Service Unavailable</h1></body></html>", "delivered_at": null, "created_at": "2026-10-18T12:00:01.904Z", "payload": { "type": "post.failed", "timestamp": "2026-10-18T12:00:01.904Z", "data": { "id": "cmgwb1n6e000bl808v5j0k8ry", "status": "failed" } } } ], "next_cursor": null}delivered_at: null means it was not delivered: it is still being tried, it failed after every try, or the webhook was paused. response_body has the start of the last answer, or why there was none, like "No answer within 10 seconds." A page has 20 deliveries; send limit for up to 100. For the next page, send next_cursor as cursor.
Send one again
Send a delivery again by its id. It goes with the same body and the same webhook-id, so your app can see it is the same event. Its tries start again from 0, with the same 8 tries. A delivered one can be sent again too.
curl -X POST https://api.postsure.dev/v1/webhooks/<webhook id>/deliveries/<delivery id>/retry \ -H "Authorization: Bearer $POSTSURE_KEY"Example response202
{ "id": "cmgx9f3kd0004l708r2v6b8nc", "event_type": "post.failed", "post_id": "cmgwb1n6e000bl808v5j0k8ry", "attempts": 0, "response_status": null, "response_body": null, "delivered_at": null, "created_at": "2026-10-18T12:00:01.904Z"}202 means the first try starts now. List the deliveries to see the answer. The webhook must be on: a paused one answers 409.
A paused webhook409
{ "error": "webhook_paused", "message": "This webhook is paused. Turn it on first: PATCH /v1/webhooks/{id} with enabled true."}A 503 with queue_unavailable means it could not be queued. Send the same request again.
Send a test event
Send a webhook.test event to check your server and your signature check. Postsure sends it once, now, and answers with your endpoint's answer. Here the signature check said no:
curl -X POST https://api.postsure.dev/v1/webhooks/<webhook id>/test \ -H "Authorization: Bearer $POSTSURE_KEY"Example response200
{ "delivered": false, "response_status": 401, "response_body": "invalid signature", "duration_ms": 87, "webhook_id": "test_5e1a7c2b-4f3d-4c8e-9b6a-2d7f0e8c1b93"}- Its body has the
typewebhook.test, atimestamp, anddata.id, the id of the webhook. It is signed like any event. webhook_idis thewebhook-idheader it was sent with, so you can find it in your logs. It starts withtest_.- A test is not saved and not sent again. It changes nothing on the webhook: a failed test is not a failed delivery. It also works while the webhook is paused.
- One test per webhook at a time. A second one answers
409withtest_in_progress. A503means the test could not be sent now: send the same request again in a minute.
Rotate the secret
Get a new secret, for example when the old one may have leaked. The reply shows the new one, this one time.
curl -X POST https://api.postsure.dev/v1/webhooks/<webhook id>/rotate-secret \ -H "Authorization: Bearer $POSTSURE_KEY"Example response200
{ "id": "cmgx2c8wd0001l708h3k5n7pq", "url": "https://example.com/hooks", "enabled": true, "previous_secret_expires_at": "2026-10-23T10:15:00.000Z", "updated_at": "2026-10-22T10:15:00.000Z", "secret": "whsec_NEWsecretEXAMPLEonlyEXAMPLEonlyEX"}Until previous_secret_expires_at, 24 hours later, every event is signed with both secrets, the new one first. So your check works with either secret. Put the new secret on your server within those 24 hours. After that, only the new secret signs.
Rotate again within the 24 hours, and the oldest secret stops signing at once.
Pause and turn on again
Postsure pauses a webhook by itself after 5 failed deliveries in a row. You can pause one too, with {"enabled": false}. While a webhook is paused:
- Nothing is sent to it.
- No new events are saved for it, so they will not be in its list of deliveries.
- A delivery whose next try comes up ends without being sent.
Turn it on again when your server works. The secret stays the same, and failure_count goes back to 0.
curl -X PATCH https://api.postsure.dev/v1/webhooks/<webhook id> \ -H "Authorization: Bearer $POSTSURE_KEY" \ -H "Content-Type: application/json" \ -d '{"enabled": true}'Example response200
{ "id": "cmgx2d1ra0002l708m6t9w3ze", "url": "https://example.com/failed", "events": [ "post.failed" ], "enabled": true, "failure_count": 0, "previous_secret_expires_at": null, "updated_at": "2026-10-19T09:02:10.551Z"}A delivery that ended while the webhook was paused is not tried again by itself. List the deliveries and send again each one with delivered_at: null.
Change or remove a webhook
PATCH /v1/webhooks/{id}changes only the fields you send:url,eventsorenabled. The secret stays the same. A new URL must be publichttps, and a delivery still being tried goes to it on its next try.GET /v1/webhookslists your webhooks, newest first, andGET /v1/webhooks/{id}gets one. Neither shows the secret.DELETE /v1/webhooks/{id}removes a webhook. It answers204, and Postsure stops sending to it at once, also the retries still waiting.
Every call, field and error is in the API reference.