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

# Callbacks

> How INRA delivers signed order callbacks, how to verify them, and how to send a test ping.

INRA can notify your system when an offline order is identified, completed, or cancelled, so you do not have to poll continuously. Database orders complete in the place-order response and do not depend on a callback, though you can still read them from `GET /v1/orders`.

## Registering a URL

Callbacks are configured by INRA, not through the API. Email the HTTPS URL you want to use to [inraasth@inra.co.th](mailto:inraasth@inra.co.th). After a short review we register:

* the URL
* any extra allowed hosts (for a test destination)
* a signing secret, which we send to you once, out of band

There is **one callback URL per client**. It cannot be set per order. v1 has no self-service endpoint for changing the URL or rotating the signing secret; ask us to do that.

`GET /v1/webhook` shows what is configured and the last delivery. The signing secret is never returned (`secret_configured` is a boolean).

## Request shape

Event types currently sent:

| `event_type` | When |
| - | - |
| `webhook.ping` | You called `POST /v1/webhook/test` |
| `order.identified` | An offline-by-details order has been given a `company_id` |
| `order.completed` | The report is ready |
| `order.cancelled` | The order will not be fulfilled |

Each callback is an HTTPS `POST` with a JSON body:

```json theme={null}
{
  "event_id": "evt_...",
  "event_type": "order.completed",
  "created_at": "2026-11-30T04:15:00+00:00",
  "environment": "sandbox",
  "data": {
    "order_id": 1000001,
    "status": "Completed",
    "links": {
      "order": "/v1/orders/1000001",
      "report": "/v1/orders/1000001/report"
    }
  }
}
```

Headers you should read:

| Header | Purpose |
| - | - |
| `X-INRA-Signature` | `v1=<hex>` HMAC-SHA256 signature |
| `X-INRA-Timestamp` | Unix timestamp used in the signed string |
| `X-INRA-Event-Id` | Stable event id for de-duplication |

## Verify the signature

The signed string is `<X-INRA-Timestamp>.<raw body>` (the exact bytes of the body, not a re-serialised JSON document). The header value is `v1=` followed by the hex digest of HMAC-SHA256 over that string, using the signing secret.

```python theme={null}
import hashlib
import hmac
import time

def verify_inra_signature(secret: str, timestamp: str, body: bytes, signature_header: str, max_age=300) -> bool:
    try:
        version, received = signature_header.split("=", 1)
    except ValueError:
        return False
    if version != "v1":
        return False
    try:
        if abs(time.time() - int(timestamp)) > max_age:
            return False
    except ValueError:
        return False
    expected = hmac.new(
        secret.encode("utf-8"),
        f"{timestamp}.".encode("ascii") + body,
        hashlib.sha256,
    ).hexdigest()
    return hmac.compare_digest(expected, received)
```

Rules:

* Reject timestamps older than five minutes (clock skew included).
* De-duplicate on `X-INRA-Event-Id` (or `event_id` in the body).
* Answer with a `2xx` within 10 seconds. Other answers, and timeouts, are retried with backoff for about 35 hours.
* Fetch the order and the report from the API after you accept the event. Treat the callback as a signal, not as the only copy of the data.

## Test ping

`POST /v1/webhook/test` queues a signed `webhook.ping` to the configured URL. You may pass a `url` whose host is on the allowed-hosts list. Check the outcome with `GET /v1/webhook`.

```bash theme={null}
curl -s -H "Authorization: Bearer $TOKEN"   -H "Accept: application/json"   -X POST https://partners-sandbox.inra.co.th/v1/webhook/test
```

If no callback URL has been registered, or the optional test `url` is not on the allowed-hosts list, the API returns `422` with the code `callback_url_not_allowed`. If the delivery path is temporarily unavailable you may see `503` with the code `service_unavailable`.


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