# Webhooks

> Sendtide webhooks: all events, verifying the signature with examples for Node.js, Python and PHP, retries over 24 hours, resending and replay.

URL: https://sendtide.ch/en/docs/webhooks/

Instead of asking whether an email arrived, you have every event sent to you as a signed HTTP request. Sendtide retries failed deliveries for 24 hours.
## Create a webhook

```
curl https://api.sendtide.ch/v1/webhooks \
  -H "Authorization: Bearer $SENDTIDE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/webhooks/sendtide",
    "events": ["email.delivered", "email.bounced", "email.complained"]
  }'
```
- url must be https and publicly reachable. Addresses in internal networks (loopback, private ranges) are blocked. Sendtide does not follow redirects.
- events empty or omitted means all events.
- The answer holds the signing secret (secret), only this once. Store it safely.

The dashboard has the same functions. With POST /v1/webhooks/{id}/test you send a test event at once and see status, duration and error.

During development you need no public address: sendtide listen --forward-to http://localhost:3000/webhooks forwards the events, signed, to your machine, see [CLI](https://sendtide.ch/en/docs/cli/).
## Events
| Event | When |
| --- | --- |
| email.queued | Sendtide accepted the email. |
| email.sent | The email was handed to the mail provider. |
| email.delivered | The recipient’s server accepted it. |
| email.delayed | Delivery is delayed, Sendtide keeps trying. |
| email.opened | A person opened it, see [Tracking](https://sendtide.ch/en/docs/tracking/). |
| email.machine_opened | Only a proxy or scanner loaded the pixel. |
| email.clicked | A link was clicked. |
| email.bounced | Rejected. data.classification and the recipient details say why. |
| email.complained | The recipient reported the email as spam. |
| email.rejected | The mail provider refused the email (data.reason). |
| email.failed | Sending failed (data.error). |
| email.suppressed | The recipient is on the [suppression list](https://sendtide.ch/en/docs/suppressions/), nothing was sent. |
| email.canceled | The email was canceled. |
| email.unsubscribed | Someone unsubscribed through the link. |
| email.received | An [inbound email](https://sendtide.ch/en/docs/inbound-email/) arrived. |
## Request body

Sendtide sends a POST with JSON:

```
{
  "id": "evt_1042",
  "type": "email.bounced",
  "created_at": "2026-12-01T08:00:03Z",
  "data": {
    "email_id": "msg_8kq2m4bt",
    "from": "hello@example.com",
    "to": ["anna@example.org"],
    "subject": "Welcome",
    "tags": ["welcome"],
    "metadata": { "order_id": "1042" },
    "stream": "transactional",
    "bounce_type": "permanent",
    "classification": "unknown_user"
  }
}
```

data always carries email_id, from, to, subject, tags, metadata and stream, plus fields that depend on the event (link, machine_kind, bounce_type, classification, smtp_response and others). Bounces have a class (classification): unknown_user, bad_domain, invalid_address, mailbox_disabled, mailbox_full, message_too_large, policy_block, auth_failed, content_rejected, attachment_rejected, suppressed, routing_error, transient, permanent_unknown, unknown. The id evt_… of an event is stable, also across retries.

Answer every request with any 2xx status, as fast as you can. Do longer work afterwards in a queue. Sendtide waits at most 10 seconds.
## Verify the signature

Every request carries the header Sendtide-Signature:

```
Sendtide-Signature: t=1795000000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
```

t is the time in Unix seconds, v1 the HMAC-SHA256 (hex) of the string "<t>.<body>" with the secret of the webhook. To verify it:
- Use the raw body, not JSON that you parsed and serialized again.
- Compute the HMAC and compare with a constant-time comparison.
- Reject requests whose t differs by more than 5 minutes from your clock (protection against replay).

```
import crypto from "node:crypto";
import express from "express";

const app = express();
const SECRET = process.env.SENDTIDE_WEBHOOK_SECRET;

app.post("/webhooks/sendtide", express.raw({ type: "application/json" }), (req, res) => {
  const header = req.get("Sendtide-Signature") ?? "";
  const parts = Object.fromEntries(header.split(",").map((p) => p.trim().split("=")));
  const t = Number(parts.t);
  const expected = crypto.createHmac("sha256", SECRET).update(`${parts.t}.`).update(req.body).digest("hex");

  const fresh = Math.abs(Date.now() / 1000 - t) <= 300;
  const valid =
    parts.v1 &&
    parts.v1.length === expected.length &&
    crypto.timingSafeEqual(Buffer.from(parts.v1), Buffer.from(expected));
  if (!fresh || !valid) return res.sendStatus(400);

  const event = JSON.parse(req.body);
  if (event.type === "email.bounced") markInvalid(event.data.to);
  res.sendStatus(200);
});
```

```
import hashlib, hmac, json, os, time
from flask import Flask, request

app = Flask(__name__)
SECRET = os.environ["SENDTIDE_WEBHOOK_SECRET"].encode()

@app.post("/webhooks/sendtide")
def sendtide_webhook():
    header = request.headers.get("Sendtide-Signature", "")
    parts = dict(p.strip().split("=", 1) for p in header.split(",") if "=" in p)
    body = request.get_data()  # raw body

    signed = parts.get("t", "").encode() + b"." + body
    expected = hmac.new(SECRET, signed, hashlib.sha256).hexdigest()
    fresh = abs(time.time() - int(parts.get("t", "0"))) <= 300
    if not fresh or not hmac.compare_digest(parts.get("v1", ""), expected):
        return "", 400

    event = json.loads(body)
    if event["type"] == "email.bounced":
        mark_invalid(event["data"]["to"])
    return "", 200
```

```
<?php
$secret = getenv('SENDTIDE_WEBHOOK_SECRET');
$body = file_get_contents('php://input'); // raw body
$header = $_SERVER['HTTP_SENDTIDE_SIGNATURE'] ?? '';

$parts = [];
foreach (explode(',', $header) as $part) {
    [$k, $v] = array_pad(explode('=', trim($part), 2), 2, '');
    $parts[$k] = $v;
}
$t = (int) ($parts['t'] ?? 0);
$expected = hash_hmac('sha256', $t . '.' . $body, $secret);

if (abs(time() - $t) > 300 || !hash_equals($expected, $parts['v1'] ?? '')) {
    http_response_code(400);
    exit;
}

$event = json_decode($body, true);
if ($event['type'] === 'email.bounced') {
    mark_invalid($event['data']['to']);
}
http_response_code(200);
```

The SDKs ship this check ready to use (verifyWebhook, verify_webhook, Webhook::verify), see [SDKs](https://sendtide.ch/en/docs/sdks/#verify-webhooks).
## Retries

If your endpoint does not answer with 2xx, or takes longer than 10 seconds, Sendtide tries again with growing gaps:
| Attempt | Wait afterwards |
| --- | --- |
| 1 | 30 seconds |
| 2 | 2 minutes |
| 3 | 10 minutes |
| 4 | 30 minutes |
| 5 | 1 hour |
| 6 | 2 hours |
| from 7 | every 4 hours |

After 24 hours Sendtide gives up on the delivery (failed). If everything fails for 24 hours, Sendtide disables the webhook (enabled: false, disabled_reason: deliveries failed for 24 hours) and writes to the owners and admins. Re-enable it with PATCH /v1/webhooks/{id} and {"enabled": true}.

Because deliveries are retried and events do not necessarily arrive in order, your code should be idempotent: store the id evt_… and ignore known ones. For state changes, check the status in the API instead of relying on order.
## Inspect and resend deliveries

GET /v1/webhooks/{id}/deliveries lists the deliveries, newest first, with status (pending, delivered, failed), attempts, last HTTP status and error. Filter with ?status=failed.

You resend a single delivery like this:

```
curl -X POST https://api.sendtide.ch/v1/webhooks/wh_1/deliveries/42/retry \
  -H "Authorization: Bearer $SENDTIDE_API_KEY"
```

That creates a new delivery with the same event (same evt_… id). If the original is still pending the API answers 409 delivery_pending, for a disabled webhook 409 webhook_disabled.
## Replay

After an outage of your server you fetch the events you missed in a time range:

```
curl https://api.sendtide.ch/v1/webhooks/wh_1/replay \
  -H "Authorization: Bearer $SENDTIDE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "2026-11-28T00:00:00Z",
    "to": "2026-11-29T00:00:00Z",
    "events": ["email.bounced"]
  }'
```
- At most 7 days back and at most 50,000 events (otherwise 422 too_many_events).
- Only the event types of the webhook are sent, further limited by events if you give it.
- Every event gets a new delivery with its old id.
- Events that still have a pending delivery are skipped. So repeating a replay sends nothing twice.
- email.received and email.unsubscribed cannot be replayed.
