Skip to content
CaptiFi Connect

Developer docs

Webhooks: delivery reports, replies and opt-outs

Webhooks push events to your server as they happen: a text sent, delivered or failed, a reply arriving, someone opting out or tapping a tracked link. Every request is signed, so you can be sure it came from us.

Adding an endpoint

In the dashboard go to Developers, Webhooks, add your HTTPS URL and tick the events you want. We show the signing secret once, when you create the endpoint; keep it with your other secrets. You can rotate it later, and send a test event to check everything is wired up. Through the API it's POST /webhooks, and POST /webhooks/{id}/test sends a test event.

An account can have up to 10 endpoints. The URL has to be reachable on the public internet: we refuse addresses on private networks, and we don't follow redirects.

An endpoint created with a test key is marked test_only and receives events about test texts only, so a test server never sees a real customer's text. Endpoints made in the dashboard or with a live key receive every event you pick, test ones included (check data.test).

Events

EventWhen it fires
message.sentA text has left us for the network. Test texts get this too, about a second after you send.
message.deliveredThe network confirmed the phone received it.
message.failedThe text failed before it left us (refunded), or the network could not deliver it (status undelivered, not refunded). Check data.status and data.error_code.
message.cancelledA text was cancelled before it left, by you, because the number opted out, or by us. Its credits are refunded.
message.receivedSomeone texted one of your numbers. data is the inbound message, including body and from.
opt_out.createdA number is now on your opt-out list. data.source says how: keyword (they texted STOP, or a short text starting with it such as "Stop please"), link (they confirmed the opt-out link in a text), manual (added in the dashboard), api or import.
opt_out.deletedA number came off your opt-out list: they texted START, or someone removed it in the dashboard or through the API. data.removed_via says which, and data.reason carries the reason given.
link.clickedSomeone tapped a tracked link. data carries the link, its destination, the message and campaign it was in, the recipient number and the click count.

The message events carry the same message object the API returns from GET /messages/{id}, so client_ref comes back to you on every one. That's the easy way to match an event to a booking or order in your own system.

What we send

A POST with a JSON body and three headers. X-Connect-Event names the event, X-Connect-Delivery identifies this delivery (it stays the same on retries), and X-Connect-Signature carries the signature.

message.delivered
POST /your/webhook/path HTTP/1.1
Content-Type: application/json
X-Connect-Event: message.delivered
X-Connect-Delivery: whd_01J9Z8X7W6V5T4S3R2Q1P0N9MA
X-Connect-Signature: t=1760605206,v1=5f2b9c...

{
  "id": "evt_01J9Z8X7W6V5T4S3R2Q1P0N9M9",
  "type": "message.delivered",
  "created_at": "2026-10-16T09:00:06.000Z",
  "data": {
    "id": "msg_01J9Z8X7W6V5T4S3R2Q1P0N9M8",
    "direction": "outbound",
    "status": "delivered",
    "to": "+447412000001",
    "segments": 1,
    "credits": 1,
    "client_ref": "booking-1042",
    "test": false,
    "delivered_at": "2026-10-16T09:00:06.000Z"
  }
}
opt_out.created
{
  "id": "evt_01J9Z8X7W6V5T4S3R2Q1P0N9MB",
  "type": "opt_out.created",
  "created_at": "2026-10-16T09:14:10.000Z",
  "data": { "phone": "+447412000001", "source": "keyword", "note": null, "created_at": "2026-10-16T09:14:10.000Z" }
}

Checking the signature

The signature header looks like t=1760605206,v1=5f2b.... t is when we signed it (Unix seconds) and v1 is the HMAC SHA-256, in hex, of the string <t>.<raw body> using your endpoint's secret. To check it, work out the same HMAC over the body exactly as it arrived (before your framework parses it), compare the two in constant time, and turn away anything signed more than five minutes ago.

For a day after you rotate the secret the header carries two v1 values (see below), so check every v1 and accept the request if any of them matches. The examples here do.

Node.js
import crypto from 'node:crypto';

// rawBody is the request body exactly as it arrived, before any JSON parsing.
export function isFromCaptiFiConnect(rawBody, signatureHeader, secret) {
  const pairs = signatureHeader.split(',').map((p) => p.trim().split('='));
  const t = Number(pairs.find(([k]) => k === 't')?.[1]);
  const signatures = pairs.filter(([k]) => k === 'v1').map(([, v]) => v);
  if (!Number.isFinite(t) || signatures.length === 0) return false;
  if (Math.abs(Date.now() / 1000 - t) > 300) return false; // more than five minutes out

  const expected = Buffer.from(crypto.createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex'));
  // Two v1 values for a day after a rotation: any one matching is enough.
  return signatures.some((v) => {
    const given = Buffer.from(v);
    return given.length === expected.length && crypto.timingSafeEqual(given, expected);
  });
}
Python
import hashlib, hmac, time

def is_from_captifi_connect(raw_body: bytes, signature_header: str, secret: str) -> bool:
    pairs = [p.strip().split("=", 1) for p in signature_header.split(",") if "=" in p]
    timestamps = [v for k, v in pairs if k == "t"]
    signatures = [v for k, v in pairs if k == "v1"]
    try:
        t = int(timestamps[0])
    except (IndexError, ValueError):
        return False
    if abs(time.time() - t) > 300:  # more than five minutes out
        return False
    expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
    # Two v1 values for a day after a rotation: any one matching is enough.
    return any(hmac.compare_digest(expected, v) for v in signatures)
PHP
<?php
function isFromCaptiFiConnect(string $rawBody, string $signatureHeader, string $secret): bool
{
    $t = 0;
    $signatures = [];
    foreach (explode(',', $signatureHeader) as $pair) {
        [$k, $v] = array_pad(explode('=', trim($pair), 2), 2, '');
        if ($k === 't') {
            $t = (int) $v;
        } elseif ($k === 'v1') {
            $signatures[] = $v;
        }
    }
    if ($t === 0 || abs(time() - $t) > 300) {
        return false; // missing, or more than five minutes out
    }
    $expected = hash_hmac('sha256', $t . '.' . $rawBody, $secret);
    // Two v1 values for a day after a rotation: any one matching is enough.
    foreach ($signatures as $signature) {
        if (hash_equals($expected, $signature)) {
            return true;
        }
    }
    return false;
}

// $rawBody = file_get_contents('php://input');

Rotating the secret

Rotate a secret in the dashboard, or with PATCH /webhooks/{id} and { "rotate_secret": true }; the new secret comes back once. For the next 24 hours every delivery is signed with both secrets, the old one first and the new one last:

X-Connect-Signature: t=1760605206,v1=<signed with the old secret>,v1=<signed with the new secret>

So you can roll the new secret out to your servers at your own pace: a server still on the old secret and one already on the new both find a match. previous_secret_expires_at on the webhook says when the old one stops. Code that only reads the last v1 keeps working with the new secret, but will reject deliveries during the switch on any server still holding the old one.

Answering and retries

Reply with any 2xx status within 8 seconds and we count the delivery as done. Do the slow work afterwards, in a queue or a background job. Anything else (a timeout, a 4xx or 5xx, a refused connection) is a failure, and we try again after 1, 5, 30, 120, 360 and 720 minutes, then give up on that event.

If every delivery to an endpoint fails for three days, we switch it off, mark anything still waiting as failed and email the account owner. It shows as Off in the dashboard. Fix whatever was wrong, switch it back on, and new events flow again. Recent deliveries, with their status, attempts and the last status code or error, are listed under each endpoint and at GET /webhooks/{id}/deliveries, and POST /webhooks/{id}/deliveries/{delivery_id}/retry sends any of them again. We keep each delivery, with its payload, for 30 days, then delete it.

Duplicates and order

A retry can arrive after your server did handle the first attempt (say it answered a fraction too late), so store the X-Connect-Delivery value, or the event id, and skip any you've seen. Events can also arrive out of order after a retry. Use the message's status and timestamps to decide the latest state, and don't let a late message.sent overwrite a delivered.

Want to try it without spending credit? Test keys fire real, signed webhooks for texts that never leave.