---
title: 'Webhooks'
description: 'Receive purchases, products and stock levels as signed HTTPS requests as soon as they change.'
---

Instead of polling the API, scango.ch can notify your system as soon as
something changes. Every event arrives as a `POST` with a JSON body at the URL
you set up in the dashboard.

## Set up an endpoint [#setup]

In the dashboard, open **Settings → Organization → Webhooks** (admin role) and
add an HTTPS URL. Choose the events and, if needed, the stores. The dashboard
then shows the **signing secret** (`whsec_…`). **Send test** checks the
connection with a `webhook.test` event; it does not appear among the
deliveries.

## Events [#events]

| Type | When |
|---|---|
| `order.paid` | A purchase was paid (`paymentState` becomes `successful`). |
| `order.deleted` | A paid purchase was deleted. |
| `product.created` | A product was created. |
| `product.updated` | A product was changed or restored. |
| `product.deleted` | A product was deleted. |
| `stock.updated` | The stock level of an item in a store changed. |

Purchase events arrive within seconds, product and stock events within one
to two minutes. Several changes of the same stock item in that time make one
event with the current level. Linked packs (e.g. a six-pack) get no
`stock.updated` events of their own: their stock is kept on the base item.
A new product arrives once as `product.created`, even if it was changed
shortly after; later changes arrive as `product.updated`.

A store selection applies to purchases and stock; products belong to the
whole organization.

## Payload [#payload]

```json
{
  "id": "evt_3f9c2a7e5b1d4c6a8e0f2b4d6a8c0e1f",
  "type": "order.paid",
  "apiVersion": "2026-12-01",
  "occurredAt": "2026-12-05T09:12:44.120Z",
  "organizationId": "org_123",
  "data": {
    "order": {
      "id": "o_456",
      "price": 1290,
      "paymentState": "successful",
      "store": "store_1",
      "products": [{ "productId": "p_1", "title": "Mineral water 50cl", "quantity": 2, "price": 120 }]
    }
  }
}
```

`data` holds the same fields as the API: `order` like
[`GET /orders/{orderId}`](/en/api-reference/orders/get-order), `product` like
[`GET /products/{productId}`](/en/api-reference/products/get-product) and `stock` with
`id`, `productId`, `storeId`, `quantity`, `minQuantity`, `maxQuantity`,
`stockStatus`, `baseUOM` and `lastUpdate`. Amounts are in Rappen, times in UTC.

## Verify the signature [#signature]

Requests follow [Standard Webhooks](https://www.standardwebhooks.com/), which
has libraries for many languages. Every request carries three headers:

| Header | Content |
|---|---|
| `webhook-id` | The event id, the same on every retry |
| `webhook-timestamp` | Unix seconds of the attempt |
| `webhook-signature` | `v1,` + base64 of HMAC-SHA256 over `{id}.{timestamp}.{body}` |

The HMAC key is the base64-decoded part of the secret after `whsec_`. Verify
the signature over the unchanged body and reject requests whose timestamp is
more than five minutes off.

```js JavaScript
import { Webhook } from "standardwebhooks";

const webhook = new Webhook(process.env.SCANGO_WEBHOOK_SECRET);

app.post("/scango", express.raw({ type: "application/json" }), (req, res) => {
  const event = webhook.verify(req.body.toString(), req.headers);
  // … put it on a queue, then answer right away
  res.sendStatus(204);
});
```

## Delivery and retries [#retries]

- Any `2xx` answer within 10 seconds counts as delivered. Redirects are not
  followed.
- Otherwise scango.ch tries again with growing gaps: first after about
  30 seconds, then each time roughly twice as long, at most 12 hours: 16
  attempts over about three days. The dashboard shows the next attempt of
  every open delivery.
- An event may arrive more than once and order is not guaranteed. Detect
  duplicates by `webhook-id` and compare `occurredAt`.
- An endpoint that fails at least ten times in a row and for two days is
  switched off and marked in the dashboard; switched on again, it starts
  counting afresh. There you can see every delivery of the last 30 days and
  send it again.
