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"}'

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.

EventWhen it is sent
post.waitingA 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.publishedThe post is live on every account.
post.partially_failedThe post is live on some accounts and not on others.
post.failedThe post failed on every account. Each target says why, in error_reason.
post.unconfirmedThe 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.delayedOne 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.

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.

EventWhen it is sent
account.connectedA connect finished, for a new account or one connected again.
account.needs_reconnectThe account stopped working and cannot post. status_reason says why and how to fix it. Sent once per change.
account.activeAn account that needed a reconnect works again, with no new connect.
account.updatedThe account's chat id, chat type, title or @name changed, and its status did not.
account.disabledPostsure turned the account off. It cannot post, and status_reason names the account to post to instead.
account.removedYou 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-signature
v1, 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.

  1. Take the secret without whsec_, and decode it from base64. That is the key.
  2. Join three things with dots: webhook-id, webhook-timestamp and the raw body. That is the signed text.
  3. Make an HMAC-SHA256 of the signed text with the key, and encode it in base64.
  4. It must match one of the signatures in webhook-signature, after v1,. Compare them in constant time.
  5. Turn down a webhook-timestamp more 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);  });}

Answer 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);

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:

TryWait before it
1At once
230 seconds
31.5 minutes
44.5 minutes
513.5 minutes
640 minutes
72 hours
86 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

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

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

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"}

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

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:

Turn it on again when your server works. The secret stays the same, and failure_count goes back to 0.

curl

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

Every call, field and error is in the API reference.