# Webhook delivery

Receive contact changes at your HTTPS endpoint instead of polling for each update.
This guide covers organisation-owned OAuth clients. Existing Zapier connections
keep their existing authentication and signing configuration.

## Set up your receiver

1. Create a client under **account menu → Settings → Integrations → API access**
   with `write` scope and save its **Webhook signing key** in your server's secret
   store. Add `read` if you also need contact polling or subscription listing.
2. Expose a public HTTPS endpoint with a valid TLS certificate.
3. Create a subscription for `contact.created`. Create a separate subscription
   for `contact.updated` if you also need changes to existing contacts.
4. Verify each delivery, save it durably, and return a `2xx` response before
   processing it asynchronously.

See [Connect your organisation](/docs/introduction#subscribe-to-signed-webhooks)
for the subscription request and [the subscription API](/api/webhooks) for its schema.

All subscriptions belonging to one organisation client use the same signing key.
The OAuth client secret is a different credential; don't use it to verify deliveries.
You can retrieve the signing key again through **Manage** in **API access**.
Rotating the one-time OAuth secret doesn't change this persistent signing key.
See [client setup and prerequisites](/docs/introduction#before-you-begin) for
organisation-admin access and active subscriptions.

## Delivery request and payload

Tapt sends an HTTP `POST` to the subscription's `target_url` with these headers:

| Header             | Value                            |
| ------------------ | -------------------------------- |
| `Content-Type`     | `application/json`               |
| `User-Agent`       | `Tapt-Webhook/1.0`               |
| `X-Tapt-Signature` | `t=UNIX_TIMESTAMP,v1=HEX_DIGEST` |

Both supported events deliver a single contact object. There is no event envelope,
event-type header, or delivery ID. Use a separate receiver path for each event type
if your integration needs to distinguish creation from updates.

This is an illustrative `contact.created` body, not a real contact:

```json
{
  "id": "contact_abc789",
  "first_name": "Jane",
  "last_name": "Doe",
  "email": "jane@example.com",
  "phone_number": "+61400000000",
  "job_title": "Community coordinator",
  "company": "Example Foundation",
  "company_website": "https://example.com",
  "company_phone_number": null,
  "note": "Met at an event.",
  "street_address": null,
  "city": null,
  "state": null,
  "country": "Australia",
  "post_code": null,
  "contact_owner_email": "staff@example.com",
  "created_at": "2026-10-13T01:00:00Z",
  "updated_at": "2026-10-13T01:00:00Z"
}
```

Use `id` as the contact's identifier in your CRM. `contact_owner_email` is the
card/profile owner's email when available, not the new contact's email. It can
be `null`; handle that case without assigning the contact to an arbitrary staff member.

## Verify the signature before processing

Capture the raw request body before JSON parsing. Compute HMAC-SHA-256 over the
timestamp, a period, and the exact body bytes, using your client's signing key.
Compare the result with the lowercase hexadecimal digest in `X-Tapt-Signature`
using a constant-time comparison.

Use the signing-key string exactly as supplied. Don't base64-decode it.
The timestamp is Unix time in seconds and describes the delivery attempt,
not the time the contact was created. Each retry gets a new timestamp and signature.

The following function rejects malformed signatures and timestamps more than
five minutes from your receiver's clock:

```javascript
import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyTaptSignature(rawBody, header, signingKey, now = Date.now()) {
  const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(header ?? "");
  if (!match || Math.abs(now / 1000 - Number(match[1])) > 300) return false;

  const expected = createHmac("sha256", signingKey).update(`${match[1]}.`).update(rawBody).digest();
  const received = Buffer.from(match[2], "hex");
  return timingSafeEqual(expected, received);
}
```

Reject an invalid signature without processing the contact. Keep your server
clock synchronized. A timestamp check limits replay age but doesn't eliminate
duplicate requests within that window.

## Acknowledge promptly

Return `200 OK`, `202 Accepted`, or another `2xx` status after you've verified the
signature and durably saved the delivery. Process slow CRM calls in a background
job rather than keeping the HTTP request open. Don't acknowledge before saving:
a successful response tells Tapt you've accepted the delivery. Still handle duplicates.

Tapt uses a five-second connection timeout and a ten-second receive timeout.
These are separate timeouts, not a guaranteed total request duration.
Redirects aren't followed. Every non-`2xx` response, including `3xx`, `4xx`, and
`5xx`, is a delivery failure. Timeouts and connection failures also cause retries.

If you can't save the delivery, return an error so Tapt can retry. If you've
already saved a duplicate, return a `2xx` response rather than requesting another retry.

## Retries and failures

Tapt makes up to **20 total attempts** for an enqueued delivery: the initial
attempt and up to 19 retries. Failed attempts use exponential backoff with
random jitter. The first few retry delays are:

| After failed attempt | Delay before the next attempt becomes eligible |
| -------------------- | ---------------------------------------------- |
| 1                    | 17–18 seconds                                  |
| 2                    | 19–20 seconds                                  |
| 3                    | 23–25 seconds                                  |
| 4                    | 31–34 seconds                                  |
| 5                    | 47–51 seconds                                  |

Later delays continue to increase and can extend over days. Queue load can delay
execution further; these are scheduling delays, not guaranteed delivery times.
Tapt doesn't use your response's `Retry-After` header to schedule webhook retries.

Retries use the same saved contact payload, not a fresh read of the contact.
They reload the subscription, so a changed `target_url` applies to subsequent
attempts. Organisation-client delivery also rechecks subscription activity and
expiry, client status, organisation ownership, and approved `write` scope.
Deleting a subscription or revoking its client prevents subsequent deliveries;
it can't recall a request already in flight.

After the final failed attempt, the delivery job is discarded and no further
automatic retry is scheduled. The subscription isn't automatically deleted.
There is no customer-facing delivery-history or replay API, and no automatic
failure-email guarantee. Monitor your receiver's errors and contact Tapt support
if you need help investigating a missed delivery.

## Handle duplicates and out-of-order updates

Delivery isn't exactly once. For example, your receiver might save a contact but
its response might be lost, causing Tapt to retry. Delivery order isn't guaranteed.

Make CRM writes idempotent by upserting on the contact's `id`. Use `updated_at`
to avoid overwriting newer data with an older retried payload. A timestamp isn't
a unique event ID, so don't assume every distinct event has a distinct timestamp.
Don't use the signature as a deduplication key: it changes on retries.

## Recover from missed deliveries

Webhooks don't replay contacts created before you subscribed. Use the
[contacts endpoint](/api/contacts) for an initial import and periodic reconciliation.
Paginate through the results and upsert by `id`, respecting the API's
[rate limits](/docs/rate-limits).
Creation-time filtering isn't supported.

Once your receiver is healthy again, new events can still arrive through the
existing subscription. Exhausted deliveries aren't automatically replayed;
reconcile them through the contacts API.
