API & Webhooks
Let your own website or internal tools read and manage products, customers, orders, coupons and gift cards (vouchers) in BazaarPOS, and get a signed message on your own server when an order, coupon or gift card changes. It works the same on the desktop app (your data stays on your PC) and on the online app.
Overview
There are two parts, and each has its own on/off switch. Both are off until you switch them on.
- API access — a REST API. A program that has one of your API keys can list and create products, customers and orders, create coupons and issue, check, use and top up gift cards.
- Webhooks — when something happens, BazaarPOS sends a message (JSON) to an address on your server. You choose the address and the events.
Each business is separate: a key only ever reaches the data of the business it was made in, and events are only sent to that business's own addresses.
Step-by-Step Guide
1 Switch it on and make a key
- Open Settings → Admin → API & Webhooks.
- Switch API access on.
- Under API keys, type a name (for example "Our website"), tick Can also change data only if the program needs to create or change records, and click Make a key.
- Copy the key now. It starts with
bpk_and is shown only once. If you lose it, delete it and make a new one.
2 Call the API
The address is shown on the same screen ("Address for your developer"). A full description that Postman or Swagger can import is at /open/openapi.json.
curl https://YOUR-ADDRESS/api/v1/open/products?search=cake \
-H "Authorization: Bearer bpk_xxxxxxxxxxxxxxxx"
curl -X POST https://YOUR-ADDRESS/api/v1/open/orders \
-H "Authorization: Bearer bpk_xxxxxxxxxxxxxxxx" -H "Content-Type: application/json" \
-d '{"items":[{"productId":12,"quantity":2,"price":550}],"paymentMethod":"CASH","amountPaid":1100,
"externalRef":"WEB-ORDER-5001","metadata":{"channel":"website"}}'
A read-only key can only use GET. The limit is 300 requests a minute per key. Errors come back as {"error": "…"} with a plain sentence.
3 Add a webhook address
- Switch Webhooks on.
- Under Webhook addresses, enter a name and the address on your server (online accounts need
https://; a desktop installation may also use an address inside your own network, such ashttp://192.168.1.50:8080/hook). - Leave Send all events ticked, or untick it and choose the events you want.
- Click Add address and copy the signing secret (
whsec_…, shown once). - Click Test. Your server should answer with any 2xx status. The result appears in the Delivery log.
What the API covers
| Records | What you can do |
|---|---|
/products | List (search, page), read one, create, change |
/customers | List, read one, create, change |
/orders | List, read one with its items, create (stock and tax follow the same rules as the app), cancel (/void), refund |
/coupons | List, create (type is PERCENT or FLAT; optional maxUses, expiresAt, minOrderValue, customerId to make it for one customer), check a code against an order total (/coupons/validate), see every use (/coupons/{id}/history) |
/giftcards | List, issue, check balance (/giftcards/balance?code=), use part of it (/redeem), add money (/{id}/topup), see every use (/giftcards/{id}/history) |
Coupons and gift cards on orders
Put couponCode (and couponDiscount) and/or giftCardCode and giftCardAmount in the order, in the app or through the API:
- The amount is taken off the gift card when the order is made. If the card does not exist, has expired or does not have enough left, the order is refused and nothing is taken. Two orders at the same moment can never spend the same balance.
- A coupon is checked: switched off, expired, used up (
maxUses) or made for another customer are refused with a plain message. Every order that uses it counts as one use. A code that is not in your coupon list is accepted as before (it is only a discount amount). - If the order is cancelled or refunded, the money goes back on the card and the use goes back to the coupon.
- The history of a card or coupon lists every use with the order's invoice number and the customer. Orders read through the API show the coupon and gift card they used.
Your own ids: externalRef and metadata
Send externalRef (the id the record has in your system, up to 120 characters) and metadata (a small JSON object, up to 4000 characters) when you create or change a record. They come back on every read and are included in webhook messages. An externalRef can be used by only one record of each type, so you can never create the same order twice by mistake — the second try answers 409 and creates nothing.
GET /open/lookup/orders?externalRef=WEB-ORDER-5001 # find the BazaarPOS order for your order number
PUT /open/products/12/external-ref {"externalRef":"SHOP-77"} # attach your id to a record that already exists
Webhook events
| Event | When |
|---|---|
order.created | An order (sale) is made, in the app or through the API |
order.updated | An order is cancelled, refunded or its payment changes (data.change says which) |
coupon.created | A coupon is created |
coupon.redeemed | An order is made with a coupon code |
giftcard.issued | A gift card (voucher) is issued |
giftcard.redeemed | Part of a gift card is used (old and new balance included) |
giftcard.balance_changed | The balance changes for any reason — used or topped up (data.change is negative or positive) |
Every message looks like this:
{
"id": "evt_Qe3...", // the same id if we send it again - use it to ignore repeats
"type": "giftcard.redeemed",
"createdAt": "2026-11-19T10:15:00.000Z",
"tenantId": 1, // your business
"storeId": 1, // the branch it happened in
"data": { "id": 4, "code": "GC-WEB-1", "amount": 300, "previousBalance": 1000, "balance": 700,
"externalRef": "VOUCHER-1", "metadata": null }
}
Check that a message really came from BazaarPOS
Each message has a header X-BazaarPOS-Signature: t=<unix seconds>,v1=<hex>. Work out HMAC-SHA256(secret, t + "." + rawBody) as hex with your signing secret; it must equal v1. Use the raw body exactly as received, and refuse a message whose t is more than 5 minutes old.
// Node.js
const crypto = require('crypto');
function valid(rawBody, header, secret) {
const t = /t=(\d+)/.exec(header)[1], v1 = /v1=([0-9a-f]+)/.exec(header)[1];
const want = crypto.createHmac('sha256', secret).update(t + '.' + rawBody).digest('hex');
return Math.abs(Date.now() / 1000 - t) < 300 && crypto.timingSafeEqual(Buffer.from(v1), Buffer.from(want));
}
# Python
import hmac, hashlib, time, re
def valid(raw_body: bytes, header: str, secret: str) -> bool:
t = re.search(r"t=(\d+)", header).group(1); v1 = re.search(r"v1=([0-9a-f]+)", header).group(1)
want = hmac.new(secret.encode(), (t + ".").encode() + raw_body, hashlib.sha256).hexdigest()
return abs(time.time() - int(t)) < 300 and hmac.compare_digest(v1, want)
// PHP
function valid($raw, $header, $secret) {
preg_match('/t=(\d+)/', $header, $a); preg_match('/v1=([0-9a-f]+)/', $header, $b);
return abs(time() - $a[1]) < 300 && hash_equals(hash_hmac('sha256', $a[1] . '.' . $raw, $secret), $b[1]);
}
If your server does not answer
Answer any 2xx status within 10 seconds. Otherwise BazaarPOS tries again after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours (7 tries in all), and then marks the message Failed. The Delivery log shows every message with its status, the number of tries and the reason for the last failure, and Send again sends a failed or waiting message at once. Messages older than 30 days are removed from the log.
Where webhooks are sent from
In Settings → Advanced → Automatic jobs the owner chooses, for webhooks, Automatic, Desktop app only or Online server only (and can switch them off).
- Automatic: an event is sent by the computer or server where it happens. Things that arrive later by sync from another device are not sent again.
- Desktop app only: only the desktop app sends events.
- Online server only: the online server sends its own events and the new orders, coupons and gift cards that phones and other computers send up by sync, plus gift card balance changes, coupon uses and refunds that arrive that way. Choose this if you want one place for everything.
- Each business has its own choice. With several servers, one sends at a time, so nothing is sent twice.
- A bill that is cancelled, fully returned or paid later on a phone reaches the server by sync and is sent as
order.updated(data.changeisvoided,refundedorpayment_updated). A cancelled or returned bill never changes again.
Desktop app and online app
- Desktop app: the API runs on the shop PC and stays inside your network. Webhooks are sent from the PC itself, so an address inside your network works and no business data passes through our cloud. If the PC is off or offline, messages wait and are sent when it is back.
- Online app: the API is at the address shown on the screen. Webhook addresses must be public
https://addresses. - Orders made on a phone or another counter reach the webhook when they reach the server or PC that sends the webhooks.
Common questions
| Message | What it means |
|---|---|
| "API key missing" / "not valid" | Send the key as Authorization: Bearer bpk_… or in X-API-Key. A key that was switched off or deleted stops working at once. |
| "API access is switched off" | Switch API access on in Settings → Admin → API & Webhooks. |
| "This API key is read-only" | Make a key with Can also change data ticked. |
| "part of the Enterprise plan" | The business's licence does not include this feature. Upgrade the licence. |
| 409 on create | The externalRef is already used by another record of that type; nothing was created. |