---
title: Webhooks
description: Subscribe to account events, verify Standard-Webhooks signatures and replay deliveries — a signed JSON payload pushed to your HTTPS endpoint when one fires.
---

# Webhooks

Webhooks push a signed JSON payload to your HTTPS endpoint when an
account event fires. Signing follows the
[Standard Webhooks](https://www.standardwebhooks.com/) spec.

> Manage webhook endpoints from the dashboard (**Settings → Connected
> apps / Webhooks**) with an owner/admin session, **or programmatically**
> with any credential carrying the `webhooks:write` scope — an API key
> **or** an OAuth access token. That makes subscribe/unsubscribe usable as
> a [REST Hooks](https://zapier.com/engineering/webhook-design/) trigger
> from iPaaS platforms (Zapier, Make, n8n).
>
> The endpoint-management routes are deliberately outside the generated
> OpenAPI spec and SDK (they configure delivery infrastructure, not the
> data plane) — integrate against the request/response shapes documented
> on this page.

---

## Registering an endpoint

Register an HTTPS endpoint in your dashboard (**Settings → Webhooks**), or
programmatically with the `webhook-endpoints` API using an owner/admin
session. You choose which event types to subscribe to, and you receive the
endpoint's **signing secret exactly once** (`whsec_…`) at creation — store
it in your secret manager, as we cannot recover it.

URL safety: we reject endpoints on private/loopback IPs (10/8, 172.16/12,
192.168/16, 127/8, ::1), `file://` URLs, and the cloud-metadata address
(169.254.169.254). HTTPS is required outside local development. The URL
is re-validated at delivery time to defeat DNS-rebinding.

From there you can list endpoints, rotate the signing secret, send a test
event, browse delivery history, and replay failed deliveries.

Subscribe programmatically (the REST-Hooks pattern) with a scoped key:

```bash
curl -X POST https://api.arcnm.io/api/v1/webhook-endpoints \
  -H "X-API-Key: ak_live_…" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://hooks.zapier.com/…","event_types":["calculation.succeeded"]}'
# → 201 { "id": "…", "secret": "whsec_…" }   ← store the secret now
```

The subscribable event types are discoverable at
`GET /api/v1/webhook-endpoints/event-types` (requires `webhooks:read`) — the
machine-readable mirror of the catalog below. Unknown event types are
rejected at subscribe time with `400`, so a typo fails fast.

---

## Event envelope

The POST body is:

```json
{
  "id": "a1b2c3d4-…",
  "type": "wallet.low_balance",
  "created_at": "2026-05-28T14:23:00Z",
  "data": { "...": "event-specific payload" }
}
```

- `id` — unique event id. The same event re-delivered (retry or replay)
  keeps this `id` — **dedupe on it**.
- `type` — the event type (branch on this).
- `created_at` — ISO-8601 timestamp.
- `data` — the event-specific payload.

---

## Event catalog

Events currently delivered to customer endpoints:

| Event | When it fires |
|---|---|
| `calculation.succeeded` | A part calculation finished with a priced result. Payload: `calculation_id`, `part_id`, `part_revision_id`, `unit_cost` (to the currency's minor unit — two decimals for EUR — as `GET /calculations/{id}` serves it), `currency`, `price_completeness` on a freshly priced result (`complete`, or `partial` when the price leaves out work the drawing asks for — then `unit_cost` is a lower bound, and the calculation's `analytics.process_plan.unpriced` lists the work with its remedies). Events from before 2026-11-18 may carry `served_from_cache: true` (a result cache that no longer exists) |
| `calculation.failed` | A part calculation terminated with an error — whether the run itself failed or the platform determined before running that it cannot be priced. Payload: `calculation_id`, `error`, and `reason` (a stable code for the refusal, such as `no_feasible_machine`) when the platform determined one; the calculation's `analytics.selection_failure` carries the same refusal as data |
| `wallet.credited` | The wallet was credited (top-up, refund) |
| `wallet.debited` | The wallet was debited (a charge was captured) |
| `wallet.low_balance` | Balance dropped below the configured threshold |
| `billing.prepaid_funding_needed` | Your organization is close to its included calculations with an empty balance. Top up before it runs out — past the included volume, calculations are saved but park as `blocked` until funded. Payload: `tier_slug`, `used`, `included`, `remaining`, `overage_cents`, `wallet_balance_cents` |
| `calculation.repriced` | A re-price finished — a new calculation priced from a source calculation under an assumption policy; sent next to its `calculation.succeeded`. Payload: `calculation_id`, `repriced_from_calculation_id`, `unit_cost`, `currency`, `assumption_policy`, `costing_date` |
| `market.driver_moved` | One delivery (a digest or an immediate alert) of a driver-move alert rule whose channels include `webhook`: reference values your current calculations read moved past the rule's threshold. Payload: `alert_delivery_id`, `rule_id`, `rule_name`, `kind`, `period_start`, `period_end`, `events` (each `id`, `kind`, `region_code`, `driver_key`, `qualifier`, `from_value`, `to_value`, `delta_pct`, `severity`, `detected_at`), `calculations` (how many are exposed) |
| `environment.version_published` | One delivery of a version-published alert rule: an environment one of your environments follows (installed from Environments) published a new version. Payload: `alert_delivery_id`, `rule_id`, `rule_name`, `kind`, `period_start`, `period_end`, `versions` (each `version_id`, `version_label`, `environment_id`, `environment_name`, `detected_at`) |
| `calculation.reprice_recommended` | One delivery of a cost-impact alert rule: market moves changed the estimated unit cost of current calculations past the rule's threshold. The figures are first-order estimates from stored cost shares — re-price to confirm them. Payload: `alert_delivery_id`, `rule_id`, `rule_name`, `kind`, `period_start`, `period_end`, `events`, `calculations` (up to 50, each `calculation_id`, `part_id`, `environment_id`, `currency`, `estimated_delta_pct`, `annual_impact`), `totals` (`calculations`, `annual_impact_eur`, `currency_note`) |
| `nest_run.solved` | A job nest finished: every material and thickness is nested. Payload: `run_id`, `env_id`, `status`, `sheets`, `lines`, `copies` — the counts `GET /nest-runs/{run_id}` shows |
| `nest_run.failed` | A job nest stopped before every material and thickness was nested; what it nested before stands. Same payload; `GET /nest-runs/{run_id}` carries the `error` |
| `assembly.settled` | An assembly's total settled — the first time it is priced, and again each time it is re-totalled after a component changed. Payload: `calculation_id`, `unit_cost` (to the currency's minor unit), `currency`, `priced_complete` (`false` while a component has no price: `unit_cost` is then a lower bound), `n_priced`, `n_unique` |
| `calibration.run.completed` | A calibration run took effect in a costing environment. Payload: `run_id`, `env_id`, `run_kind` (`teach`, `finalize` or `revert`, as the environment's run history names it), `status` |
| `endpoint.test` | Sent by the `/test` endpoint (see below) |

A multi-environment batch emits one `calculation.succeeded` /
`calculation.failed` per cell that reaches a result — a cell parked
`blocked` emits nothing until it runs — and there is
deliberately no aggregate batch event; poll
`GET /calculations/batches/{batch_id}/comparison`
and read its `complete` flag to know when the whole grid has landed.

You can subscribe to a whole namespace with a wildcard (`calculation.*`,
`wallet.*`) or to everything with `*`. Event-type names are a stable,
versioned contract (`since` v1) — we add new names rather than repurpose
existing ones.

> The catalog is expanding. Subscribe only to the event types you need;
> unknown future types won't be delivered unless you subscribe to them.

---

## Verifying signatures

Every delivery carries the Standard-Webhooks headers:

```http
webhook-id:        a1b2c3d4-…
webhook-timestamp: 1716508800
webhook-signature: v1,K5oP…base64…==
```

To verify, recompute the HMAC-SHA256 over
`{webhook-id}.{webhook-timestamp}.{raw_body}` using your endpoint
secret, base64-encode it, prefix `v1,`, and compare constant-time
against (any of) the space-separated signatures in `webhook-signature`.
Reject if the timestamp is too old.

<CodeTabs>

```python title="Python"
import base64, hmac, hashlib, time, json, os
from fastapi import FastAPI, Request, HTTPException

SECRET = os.environ["ARCNM_WEBHOOK_SECRET"]      # whsec_…
TOLERANCE_S = 300
app = FastAPI()

def _key(secret: str) -> bytes:
    raw = secret[len("whsec_"):] if secret.startswith("whsec_") else secret
    return base64.urlsafe_b64decode(raw + "=" * (-len(raw) % 4))

def verify(raw_body: bytes, headers) -> dict:
    wid = headers["webhook-id"]
    ts  = headers["webhook-timestamp"]
    sigs = headers["webhook-signature"].split(" ")
    if abs(time.time() - int(ts)) > TOLERANCE_S:
        raise HTTPException(400, "stale_signature")
    signed = f"{wid}.{ts}.".encode() + raw_body
    mac = base64.b64encode(hmac.new(_key(SECRET), signed, hashlib.sha256).digest()).decode()
    expected = f"v1,{mac}"
    if not any(hmac.compare_digest(expected, s) for s in sigs):
        raise HTTPException(400, "bad_signature")
    return json.loads(raw_body)

@app.post("/arcanum")
async def hook(req: Request):
    event = verify(await req.body(), req.headers)
    # …handle by event["type"]
    return {"received": event["id"]}
```

```typescript title="TypeScript"
import { createHmac, timingSafeEqual } from "node:crypto"
import express from "express"

const SECRET = process.env.ARCNM_WEBHOOK_SECRET!   // whsec_…
const TOLERANCE_S = 300
const app = express()
app.use(express.raw({ type: "application/json" }))   // keep raw bytes

function key(secret: string) {
  const raw = secret.startsWith("whsec_") ? secret.slice(6) : secret
  return Buffer.from(raw, "base64url")
}

function verify(rawBody: Buffer, headers: Record<string, string>) {
  const wid = headers["webhook-id"]
  const ts = headers["webhook-timestamp"]
  if (Math.abs(Date.now() / 1000 - Number(ts)) > TOLERANCE_S) throw new Error("stale_signature")
  const signed = Buffer.concat([Buffer.from(`${wid}.${ts}.`), rawBody])
  const mac = createHmac("sha256", key(SECRET)).update(signed).digest("base64")
  const expected = `v1,${mac}`
  const ok = headers["webhook-signature"].split(" ").some(
    (s) => s.length === expected.length && timingSafeEqual(Buffer.from(s), Buffer.from(expected)),
  )
  if (!ok) throw new Error("bad_signature")
}

app.post("/arcanum", (req, res) => {
  verify(req.body as Buffer, req.headers as Record<string, string>)
  const event = JSON.parse((req.body as Buffer).toString())
  res.json({ received: event.id })
})
```

</CodeTabs>

---

## Retry & failure handling

- A `2xx` response means the delivery succeeded.
- Any other status (or a timeout, ~10s) is retried with jittered
  backoff at roughly: **+5s, +5m, +30m, +2h, +5h, +10h, +24h** (an
  initial attempt plus 7 retries).
- An endpoint is auto-disabled after **20 consecutive failures**, or if
  its failure rate exceeds 50% over a 2-hour window (with enough
  samples). We email the org owner.
- Re-enable a disabled endpoint from the dashboard.

Replay a failed delivery from the dashboard — it keeps the original event
`id`, so your dedupe still works.

---

## Test events

Send a synthetic `endpoint.test` event to a single endpoint from the
dashboard. Its `data` carries a short `message` and the `endpoint_id` — use
it to bootstrap your handler before real events fire.

---

## See also

- [Errors](./errors.md) — verification failures, replay errors.
- [Idempotency](./idempotency.md) — dedupe on the event `id`.
- [Authentication](./authentication.md) — `webhooks:read` / `webhooks:write`.
