Skip to content
SnapHTML
Esc
↑↓navigate↵open⌘Jpreview
On this page

Webhooks

Register a URL and SnapHTML posts to it when a batch ends, so you do not have to poll for the ending.

A batch answers with an id and finishes minutes later. Polling for the ending works and is documented, but it is a loop you write, tune and pay for in requests. A webhook is a line of configuration instead: register a URL, and SnapHTML posts to it when something ends.

curl -X POST https://api.snhtml.com/v1/webhooks \
  -H "authorization: Bearer snhtml_..." \
  -H "content-type: application/json" \
  -d '{
    "url": "https://api.example.com/hooks/snaphtml",
    "description": "Production",
    "events": ["batch.finished"]
  }'
{
  "id": "kh767...",
  "url": "https://api.example.com/hooks/snaphtml",
  "secret": "whsec_PeY7mOYpo5wLGyN9l+/MJLN3f/dsY/TTLtdBOTGeuAQ=",
  "events": ["batch.finished"]
}

That is the only time the API returns the secret. It stays readable in the dashboard under Webhooks.

The URL has to be https and reachable from the internet. For a laptop, use a tunnel.

Events

Event When
batch.finished A batch reached a final status: succeeded, partial or failed.
batch.cancelled A batch was cancelled before it finished, and its unused renders were refunded.
batch.results_expiring A finished batch’s renders are about to be deleted. Sent one to two days ahead, and only while something is still there to collect.
template.updated A template’s HTML, name or placeholders changed, so renders from it will come out different.
template.deleted A template was deleted. Renders asking for it from now on are refused.

Subscribe to a subset with events, or leave it out to receive everything — including event types added later, since an endpoint that asked for everything keeps meaning it. GET /v1/webhooks returns the list above with each type’s description, so a client offering the choice does not have to keep its own copy.

The body carries the type, when it happened, and the event itself:

{
  "type": "batch.finished",
  "timestamp": "2026-11-23T09:58:15.151Z",
  "data": {
    "batchId": "k97219s30jc1a7n81p60wj7yps8jmsz2",
    "name": "October invoices",
    "status": "partial",
    "total": 500,
    "completed": 497,
    "failed": 3,
    "finishedAt": 1795427895151
  }
}

An event tells you a batch ended; it does not carry the renders. Read the batch to collect them — the links are signed when you ask for them, so a webhook body cannot hand out a URL that has already expired.

The other two carry what you would act on. batch.results_expiring says how many renders are still there and when the first of them goes:

{
  "batchId": "k97219s30jc1a7n81p60wj7yps8jmsz2",
  "name": "October invoices",
  "status": "succeeded",
  "items": 3,
  "expiresAt": 1795884218745
}

template.updated carries the placeholders as they are now and as they were, since that is the change that breaks a caller — a request body that filled every one of them yesterday can be missing one today:

{
  "templateId": "k17d2v7e21r7djat24swezy0rh8jsdcr",
  "name": "Invoice v2",
  "variables": ["customer"],
  "previousVariables": ["customer", "total"],
  "updatedAt": 1795451009683
}

template.deleted carries the templateId, the name it had, and deletedAt. It is the one to act on if you cache templates: a render that asks for a deleted template is refused.

Verifying a delivery

Every delivery is signed with your endpoint’s secret. Verify it with a Standard Webhooks library, which exists for most languages:

import { Webhook } from "standardwebhooks";

const wh = new Webhook(process.env.SNAPHTML_WEBHOOK_SECRET!); // the whsec_... value

app.post("/hooks/snaphtml", express.raw({ type: "application/json" }), (req, res) => {
  let event;
  try {
    // The raw body, exactly as it arrived.
    event = wh.verify(req.body, req.headers);
  } catch {
    return res.sendStatus(400);
  }

  if (event.type === "batch.finished") {
    // Acknowledge first, work afterwards.
  }
  res.sendStatus(204);
});

Pass the body as it arrived. Parsing the JSON and re-serialising it changes the bytes, and the signature will not match.

Each delivery also carries a webhook-id, which stays the same across retries and is the same for every endpoint that received the event. Use it as an idempotency key if an event arriving twice would cost you something.

When your endpoint is down

Any 2xx is a success. Anything else is retried, including a 404 — a route that has not shipped yet usually exists by the next attempt. Retries continue for about eighteen hours, then the delivery is marked failed, and you can Replay it from the dashboard once the endpoint is back.

An endpoint that fails continuously for five days is disabled, and the reason is shown next to it. Send a test delivery to check a fix, then enable it again.

Redirects are not followed: a 3xx is a failure. Register the URL you want the body to arrive at.

Rotating a secret

curl -X POST https://api.snhtml.com/v1/webhooks/kh767.../secret \
  -H "authorization: Bearer snhtml_..."

Both secrets are accepted for 24 hours, so you can update your receiver at any point in that window without dropping a delivery. After it, only the new one.

Managing endpoints

Route What it does
GET /v1/webhooks List endpoints, with the event types you can subscribe to. Secrets are never in a listing.
POST /v1/webhooks Register one, and return its secret once.
PATCH /v1/webhooks/<id> Change the URL, description or events, or set status to enabled or disabled.
DELETE /v1/webhooks/<id> Remove the endpoint and its delivery log.
POST /v1/webhooks/<id>/secret Rotate the signing secret.

An account may register ten endpoints — enough for production, staging and a laptop tunnel.

From the dashboard

The Webhooks tab does all of the above, plus two things the API does not: Send test posts a webhook.test event shaped like a real one, so you can prove the plumbing before a batch rides on it, and Replay re-sends a failed delivery. The delivery log keeps 30 days: the event, the endpoint, the attempt count, the response status, and the error.

From an agent

The MCP server exposes list_webhooks, create_webhook, update_webhook, delete_webhook and get_webhook_deliveries, so an agent that queues a batch can set up the callback it needs rather than polling for the ending. See MCP server.

Was this page helpful?