> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ignyt.si/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks and event polling

> Get notified when payments, orders and catalogs change, and verify every notification.

Event delivery
Ignyt sends a signed HTTPS request to your endpoint when something changes. If you can't receive webhooks, read the same events from the event feed.

## 1. Register an endpoint

Pick the [event types](https://docs.ignyt.si/event-types.md) you need and register a public HTTPS URL. This needs the `webhooks:manage` scope and the webhooks feature in your plan.

```bash theme={"theme":{"light":"github-light","dark":"vesper"}}
curl -X POST "$IGNITE_API_BASE_URL/v1/webhook-endpoints" \
  -H "Authorization: Bearer $IGNITE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Order updates", "url": "https://your-app.example.com/ignyt/webhooks",
       "event_types": ["order.purchase.updated", "order.merchant_order.updated", "money.payment.updated"]}'
```

```json Response (abridged) theme={"theme":{"light":"github-light","dark":"vesper"}}
{
  "id": "whk_01M8NWKC1PG5TS8CPK7A7PNYH3",
  "revision": 1,
  "url": "https://your-app.example.com/ignyt/webhooks",
  "event_types": ["order.purchase.updated", "order.merchant_order.updated", "money.payment.updated"],
  "status": "active",
  "environment": "sandbox",
  "secret": "<shown-once>"
}
```

Store `secret` in your secret manager now. It is shown only once.

The URL must be public HTTPS on port 443. A private or local address returns `422 webhook_url_not_public`, and a host that doesn't resolve returns `422 webhook_host_unresolvable`.

## 2. Verify the signature

Every request has an `Ignite-Signature` header like `t=1764495000,v1=5f0c…`. `t` is a Unix timestamp and `v1` is an HMAC-SHA256 of the string `"{t}.{raw body}"`, using your endpoint secret, as lowercase hex.

Verify against the **raw request body bytes**, before parsing the JSON. Reject requests whose timestamp is more than 5 minutes old.

```python Python SDK theme={"theme":{"light":"github-light","dark":"vesper"}}
from ignite_sdk import verify_webhook

# During secret rotation, pass the previous secret as well; drop it once rotation finishes.
event = verify_webhook(raw_body, signature_header, secrets=(current_secret, previous_secret))
```

```typescript Node.js SDK theme={"theme":{"light":"github-light","dark":"vesper"}}
import { verifyWebhook } from '@808labs/ignite-sdk';

// During secret rotation, pass the previous secret as well; drop it once rotation finishes.
const event = verifyWebhook(rawBody, signatureHeader, [currentSecret, previousSecret]);
```

```python Without an SDK theme={"theme":{"light":"github-light","dark":"vesper"}}
import hashlib, hmac, time

def verify(raw_body: bytes, header: str, secrets: list[str]) -> bool:
    """Pass the current secret, plus the previous one while a rotation is in progress."""
    parts = dict(item.split("=", 1) for item in header.split(","))
    timestamp, signature = parts["t"], parts["v1"]
    if abs(time.time() - int(timestamp)) > 300:
        return False
    signed = timestamp.encode() + b"." + raw_body
    return any(
        hmac.compare_digest(hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest(), signature)
        for secret in secrets
    )
```

## 3. Store first, then process

1. Verify the signature.
2. Save the event in your database, keyed by its `id`, and mark it unprocessed. If the `id` is already saved, it's a duplicate: return `2xx` and stop.
3. Return `2xx` quickly, only after the save has committed.
4. Process saved events with a background worker that picks up every unprocessed event, including ones left over after a restart. Read the current resource, such as the purchase, before deciding what to do, then mark the event processed.

> [!NOTE]
>
> Delivery is at least once, and events can arrive out of order. Use the event `id` to ignore duplicates and `revision` to ignore older updates. An event never asks you to create a new purchase or payment.

### Make actions safe to repeat

A worker can stop after acting but before marking the event processed, and several events can lead to the same action. For each action your worker takes, such as creating a shipment:

* **Key the action, not the event.** Use a key that names the action, such as `create-shipment:{purchase_id}`, so every event that leads to it shares one key. The event `id` still removes duplicate deliveries.
* **Save before you call.** Store an action record with that key, the request body and its status before the first call. Later events for the same action reuse this record instead of building a new request.
* **Retry with the same key and body.** Reusing a key with a different body returns `409`.
* **Resolve unknown outcomes first.** A timeout or a lost response doesn't mean the action failed. Look it up, for example by reading the shipment, and record the result before you retry or change it.
* **Use a new key only for a different action**, such as a second shipment.

## Test your endpoint

Send a signed synthetic event to an active, subscribed Sandbox endpoint with
`POST /v1/webhook-endpoints/{endpoint_id}/test`. Send an `Idempotency-Key` and a body such as
`{"event_type":"money.payment.updated"}`. The response includes a delivery ID, and the callback has
`"test": true`. Use it to check delivery and signature verification. In Sandbox, the
[scenario products](https://docs.ignyt.si/sandbox-testing.md) trigger real payment, order and refund events.

## Deliveries, retries and replays

Ignyt retries failed deliveries. To see what happened, use `GET /v1/webhook-deliveries`, `GET /v1/webhook-deliveries/summary` and each delivery's `/attempts`.

To resend an event, call `POST /v1/webhook-deliveries/{attempt_id}/redeliver` with an `Idempotency-Key` and a reason. A replay sends the same event `id`; it does not repeat the order or payment.

Rotate a signing secret with `POST /v1/webhook-endpoints/{endpoint_id}/rotate-secret`. Accept both the old and new secret until the rotation finishes.

## Poll the event feed instead

`GET /v1/events` returns the same events in order. It needs the `events:read` scope and the event feed feature.

```bash theme={"theme":{"light":"github-light","dark":"vesper"}}
curl "$IGNITE_API_BASE_URL/v1/events?limit=100&cursor=$LAST_CURSOR" \
  -H "Authorization: Bearer $IGNITE_API_KEY"
```

Save each page's events together with the `cursor` of the last event you stored, and request the next page from that cursor. `next_cursor` is `null` on the last page, so never overwrite your saved cursor with it. An empty page means you're caught up; keep your cursor.

Use the feed to catch up after an outage, even if you use webhooks. Polling counts toward your API usage, so poll at a steady interval with backoff.

## Related guides

> [card] [Event types](https://docs.ignyt.si/event-types.md)
>
> Every event and its payload.

> [card] [Errors and retries](https://docs.ignyt.si/errors-and-retries.md)
>
> Handle results you don't know yet.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.