REST API · HW agent 2.15.3
HW agent API
One API for a web application, a POS program and a server: registers, terminals and SBP, printing, scales, displays, scanners, marking.
Getting started
- 1Address. The agent runs on the computer with the devices and listens on
http://localhost:7790(the port isserver.port). From a browser on this computer — a plainfetch, from a program — any HTTP client; from a server — through the cloud. - 2Access. A site with a foreign address (the
Originheader) must be on the allowed list: a new site getsSITE_NOT_ALLOWEDand the cashier gets an “allow” request in the tray. Programs on this computer (noOrigin) pass at once. If the agent has an API token —Authorization: Bearer …; a site with a signing key signs requests on its server. - 3Devices. Devices are added on the agent page; their numbers are in
GET /api/v1/devices:/registers/1,/terminals/2,/scales/3. - 4Format. JSON; amounts — integer kopecks; enums — strings (
SELL,CARD,VAT20); dates — ISO 8601; errors — problem+json with acodefield. No hardware — use the register, terminal, scale and printer emulators.
Principles
Operations
Everything that changes a device state is an operation: POST returns its snapshot {id, type, status, stage, result, error, warnings}. status: QUEUED → RUNNING → SUCCEEDED or FAILED; UNKNOWN — the agent restarted or the device did not answer, check the result on the device. On one device operations run in order, on different devices in parallel.
Retries
Every POST that starts an operation carries Idempotency-Key — e.g. a UUID per cashier action. A retry with the same key returns the same operation and never charges or prints twice; the same key for another operation — IDEMPOTENCY_KEY_REUSED.
Waiting
Prefer: wait=30 — wait for the result up to 30 seconds (at most 180): 200 if the operation finished, otherwise 202 and the operation Location — ask GET /api/v1/operations/{id} or wait for an event.
Events
GET /api/v1/events — Server-Sent Events: operation on every operation change, barcode — a scanner code {deviceId, code, at}, card — a card on the reader, display — lines on the second monitor, qr — an SBP payment QR (payload: null — remove), power — power {source: AC|BATTERY, batteryPercent, minutesLeft}.
Timeouts
An operation waits for its device at most: register 120 s, terminal 300 s, receipt with card payment 420 s, printers 120 s, scales, displays and drawer 60 s (the device queue is not counted). Change them on the agent page, in hw.operations.timeouts or per request with X-HW-Timeout: 30.
Setup
The /api/v1/setup/… methods serve the agent page and work only from it; they are not described here. Devices, printers, the cashier and allowed sites are set up on the agent page or in its settings file — see the help.
A sale
- 1In one operation
POST /api/v1/checkouts— card → receipt → slip; if the receipt fails the payment is cancelled
- 2
- 3
Receipt
{
"type": "SELL", // SELL, SELL_RETURN, BUY, BUY_RETURN
"taxation": "USN_INCOME", // OSN, USN_INCOME, USN_INCOME_OUTCOME, ESHN, PATENT; absent — from Workplace or the register default
"operator": {"name": "Ivanova I.I.", "inn": "770123456789"}, // absent — the cashier from Workplace
"customer": {"contact": "+79991234567"}, // for an electronic receipt
"header": [
{"kind": "TEXT", "text": "Order 123", "align": "CENTER"},
{"kind": "PAIR", "text": "Date:", "right": "01.11.2026 19:00"},
{"kind": "SEPARATOR"}
],
"items": [
{"name": "Service", "price": 150000, "quantity": 1, "amount": 150000,
"vat": "NONE", "paymentMethod": "FULL_PAYMENT", "paymentObject": "SERVICE"}
],
"payments": [{"type": "CARD", "amount": 150000}], // CASH, CARD, PREPAID, CREDIT, OTHER
"footer": [],
"electronic": false, // true — do not print, send to the customer
"senderEmail": "kassa@example.ru", // tag 1117; absent — from Workplace
"settlementPlace": "Cash desk" // tag 1187; absent — from Workplace
}The sum of payments must equal the sum of items, an item amount — price × quantity. Text lines wrap to the register paper width automatically. Fields — the Receipt model.
Examples
Sale with a card payment — payment, receipt and slip in one operation. The response is an operation with result.receipt (FD number, fiscal sign, shift, QR code) and result.payment (paymentRef for a refund, card, RRN, authorization code, slip).
POST /api/v1/checkouts
Content-Type: application/json
Idempotency-Key: 3f6c1d9e-1b2a-4c55-9e0d-6a1f0c2b7d11
Prefer: wait=170
{"registerId": 1, "terminalId": 2, "receipt": { … }, "printSlip": true}A PDF on the ticket printer — the printer by the role set on the agent page:
POST /api/v1/print-jobs
Idempotency-Key: 7b0e…
{"urls": ["https://example.com/tickets/1.pdf"], "role": "tickets", "copies": 1}Printer commands as is — ESC/POS, ZPL; e.g. a ZPL label:
POST /api/v1/print-jobs
Idempotency-Key: 9c41…
{"raw": "XlhBXkZPNTAsNTBeQTBOLDUwXkZESGVsbG9eRlNeWFo=", "printer": "Zebra ZD220"}Operation progress and the scanner in the browser:
const events = new EventSource('http://localhost:7790/api/v1/events');
events.addEventListener('operation', e => {
const op = JSON.parse(e.data);
console.log(op.type, op.status, op.stage); // e.g. "tap the card on the terminal"
});
events.addEventListener('barcode', e => console.log(JSON.parse(e.data).code));Ready clients — SDKs for JavaScript/TypeScript, Java and C# in the agent repository (the sdk folder), see the help.