# Webhooks

> Have links.et call your server when a verification finishes, with a signed request and retries.

Send `webhookUrl` with [`POST /api/verify`](/docs/verify) and links.et calls that address when the verification finishes. You do not have to hold the request open, poll or keep a stream connected.

## Ask for one

```bash
curl -sX POST https://links.et/api/verify \
  -H "x-api-key: vk_live_..." \
  -H "content-type: application/json" \
  -d '{
    "url": "https://transactioninfo.ethiotelecom.et/receipt/ABCD1234EF",
    "webhookUrl": "https://shop.example.com/hooks/links"
  }'
```

A call with `webhookUrl` returns `202` at once with a `requestId`, the same as the [async flows](/docs/integration-flows). Add `waitMs` if you also want the answer in the response when it is quick. The webhook is sent either way, so your handler is the one place that always hears the result.

`webhookUrl` must be a public `https://` address, at most 2,048 characters, with no username or password in it. Anything else is a `400 invalid_request` that says why. The address is per request, so each order or environment can use its own.

## What you receive

One `POST` with a JSON body:

```json
{
	"id": "5b1f0c1e-7c0a-4a55-9d0e-2f6a3f0c9a11",
	"type": "verification.completed",
	"createdAt": "2026-01-01T00:00:03.000Z",
	"data": {
		"requestId": "550e8400-e29b-41d4-a716-446655440000",
		"processingStatus": "completed",
		"ok": true,
		"providerKey": "telebirr",
		"resolvedUrl": "https://transactioninfo.ethiotelecom.et/receipt/ABCD1234EF",
		"httpStatus": 200,
		"fetchedAt": "2026-01-01T00:00:03.000Z",
		"cached": false,
		"error": null,
		"receipt": { "source": "telebirr-html" },
		"history": {
			"scope": "account",
			"checkedBefore": false,
			"previousChecks": 0,
			"firstCheckedAt": null,
			"lastCheckedAt": null
		}
	}
}
```

| Field | Description |
| ----------- | ---------------------------------------------------------------------------------------------------------------------- |
| `id` | The event id. The same on every retry of this event. Use it to ignore an event you have already handled. |
| `type` | `verification.completed` when the receipt verified, `verification.failed` when it did not. For screenshots, see below. |
| `createdAt` | When the verification finished. |
| `data` | The same envelope [`GET /api/verify/:requestId`](/docs/integration-flows#polling) returns for this request. |

On `verification.failed`, `data.ok` is `false`, `data.receipt` is `null` and `data.error` says why. There is one event per request.

If the request sent [`expect`](/docs/verify#paid-to-you-receivercheck), `data.receiverCheck` says whether the payment went to you and `data.amountCheck` whether it was the right amount.

These headers come with it:

| Header | Value |
| ----------------- | ----------------------------------------------------- |
| `Links-Event` | The event type, same as `type` in the body. |
| `Links-Event-Id` | The event id, same as `id` in the body. |
| `Links-Attempt` | Which attempt this is, from `1`. |
| `Links-Signature` | `t=<unix seconds>,v1=<signature>`. See the next part. |

## Screenshots

[`POST /api/verify-image`](/docs/verify-image) takes `webhookUrl` too. That call still answers in its own response, since reading a screenshot is done while you wait. The webhook is sent as well, with the same body under `data`, so your server hears the result even when the connection dropped during a slow read.

| `type` | When |
| ----------------- | -------------------------------------------------------------------------- |
| `image.completed` | The screenshot was read. `data` is the `200` response body. |
| `image.failed` | The reader failed (`detection_failed`). `data` is the `502` response body. |

`image.completed` means the read finished, not that the bank confirmed a payment: read `data.upstream` for that, the way you would on the response. The response also carries `webhook: { id, url }`, the id of the event that was queued. Calls refused up front (a bad body, a spent allowance) send no webhook.

## Check the signature

Anyone can post to your address, so check that a request came from links.et before you trust it. Each API key has a signing secret. It is on the [Webhooks page](/dashboard/webhooks) of your dashboard, or ask for it with the key:

```bash
curl -s https://links.et/api/webhooks/secret -H "x-api-key: vk_live_..."
# { "ok": true, "secret": "whsec_...", "rotated": false }
```

The signature is HMAC-SHA256, keyed with that secret, over the timestamp, a dot, and the raw request body. Compute it over the bytes you received, before you parse the JSON:

```ts
import { createHmac, timingSafeEqual } from 'node:crypto';

function isFromLinks(rawBody: string, header: string, secret: string): boolean {
	const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
	const expected = createHmac('sha256', secret).update(`${parts.t}.${rawBody}`).digest('hex');
	const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
	return (
		fresh &&
		parts.v1?.length === expected.length &&
		timingSafeEqual(Buffer.from(parts.v1), Buffer.from(expected))
	);
}
```

Refusing a timestamp more than 5 minutes old stops someone replaying a request they captured. Each retry is signed again with a fresh timestamp, so a late retry still passes.

To replace the secret, use Replace on the dashboard page or `POST /api/webhooks/secret`. The old one stops working at once, including for events already waiting to be retried.

## Answer and retries

Answer with any `2xx` within **10 seconds**. Do the real work after you answer if it is slow.

Anything else counts as a failure and is tried again: another status, a timeout, a connection error. A redirect is a failure too; links.et does not follow it.

| Attempt | When |
| ------- | ---------------------------- |
| 1 | As the verification finishes |
| 2 | 1 minute later |
| 3 | 5 minutes after that |
| 4 | 30 minutes after that |
| 5 | 2 hours after that |
| 6 | 6 hours after that |

After the sixth failure the event is dropped. Retries leave on a one-minute timer, so each can be up to a minute later than the table says.

Delivery is at least once. You can get the same event twice, for example when your `2xx` was lost on the way back. Keep the `id` of each event you handle and skip one you have seen.

## See what happened

The [Webhooks page](/dashboard/webhooks) of your dashboard lists the last 50 webhooks on your account: where each went, how many attempts it took and what your server answered.

From code, `GET /api/verify/:requestId` carries a `webhook` object for a request that asked for one:

```json
"webhook": {
	"url": "https://shop.example.com/hooks/links",
	"status": "pending",
	"attempts": 2,
	"lastStatus": 500,
	"lastError": "answered HTTP 500",
	"nextAttemptAt": "2026-01-01T00:06:03.000Z",
	"deliveredAt": null
}
```

`status` is `scheduled` while the verification is still running, `pending` while there are attempts left, `delivered` once you answered `2xx`, and `failed` when links.et gave up. The result itself stays readable there for 30 days whether or not the webhook got through.

## Good to know

- **An address that resolves to a private network is refused.** `localhost`, `10.x`, `192.168.x` and the like never get a request. To test from your laptop, put a public tunnel in front of your handler.
- **With an `Idempotency-Key`, the first call decides.** A replay with the same key does not start a second verification or a second webhook, and a different `webhookUrl` on the replay is ignored.
- **A webhook costs nothing extra.** The verification counts toward your plan the way it would without one.
