ocapi-shop Webhooks API
Webhooks push the store's events to a URL of yours as they happen, instead of you polling for them. Owners only. A store has up to 10 endpoints (IDs `whk_`), each listening for some of these events: | Event | When | | --- | --- | | `order.created` | An order is placed or recorded | | `order.updated` | An order's `order_status`, `payment_status` or tracking changes | | `order.paid` | An order's payment becomes `paid` (it also sends `order.updated` when it changes) | | `product.created`, `product.updated`, `product.deleted` | A product is created, edited (reordering doesn't count) or deleted | Creating an endpoint subscribes it and deleting it unsubscribes it, which is how Zapier's REST hooks work. Each event is a `POST` with a JSON body: ```json { "id": "evt_...", "type": "order.created", "created_at": "2026-01-01T12:00:00.000Z", "store_id": "str_...", "data": { ...the order, exactly as Get an order returns it } } ``` `data` is the resource as this API returns it (an Order or a Product; a deleted product as it was). The `webhooks` section of this spec documents each event. Requests also carry the headers `Ocapi-Event-Id`, `Ocapi-Event-Type` and `Ocapi-Delivery-Id`. ## Verifying signatures Every request has an `Ocapi-Signature` header like `t=1767268800,v1=5257a869...`: 1. Split it on `,` and take `t` (a Unix timestamp) and `v1` (a hex digest). 2. Compute HMAC-SHA256 of `.`, keyed with the endpoint's `secret` (`whsec_...`), as lowercase hex. 3. Compare it with `v1` in constant time, and reject a `t` more than 5 minutes from now so an old request can't be replayed. ```ruby t, v1 = header.split(",").map { it.split("=", 2) }.to_h.values_at("t", "v1") expected = OpenSSL::HMAC.hexdigest("SHA256", secret, "#{t}.#{raw_body}") valid = ActiveSupport::SecurityUtils.secure_compare(expected, v1) && (Time.now.to_i - t.to_i).abs <= 300 ``` Use the raw body as received; parsing and re-serializing the JSON changes it. ## Delivery and retries Answer with any 2xx status within 10 seconds. Anything else (an error, a timeout, a redirect) is retried with growing waits (1 minute, 5 minutes, 25 minutes, then hours) for up to 8 attempts over about 12 hours. Events can arrive more than once or out of order: use the event `id` to skip duplicates and the resource's `updated_at` to keep the newest. After 15 failed attempts in a row Ocapi turns the endpoint off (`active: false`, with `disabled_at`) and emails the store's owner; turn it back on with Update a webhook. URLs must be HTTPS and reach a public address.