Server, CRM, bot
Through the cloud
The same agent API — from your server, with no browser on site: the hw-cloud cloud passes the request to the register over its outgoing connection (the register is behind NAT, no inbound ports). Path, method, body and response are the agent's, including images and PDF.
Address and key
The base address is https://cloud.hw-connector.ru/agent instead of http://localhost:7790, everything else is unchanged. Instead of the agent token — the account API key X-Api-Key: hwk_… from the hw-connector.ru cabinet (Cloud section), the register — X-Device-Id.
curl
# locally
curl -X POST 'http://localhost:7790/api/v1/registers/1/receipts' \
-H 'Idempotency-Key: order-123' -H 'Prefer: wait=30' \
-H 'Content-Type: application/json' --data @receipt.json
# through the cloud: another address and two headers
curl -X POST 'https://cloud.hw-connector.ru/agent/api/v1/registers/1/receipts' \
-H 'X-Api-Key: hwk_…' -H 'X-Device-Id: 42' \
-H 'Idempotency-Key: order-123' -H 'Prefer: wait=30' \
-H 'Content-Type: application/json' --data @receipt.jsonJavaScript
// The agent JS SDK (on a server, Node 18+): another address and two headers via a custom fetch
const hw = new HwConnector({
baseUrl: 'https://cloud.hw-connector.ru/agent',
fetch: (url, init = {}) => fetch(url, { ...init, headers: { ...init.headers, 'X-Api-Key': 'hwk_…', 'X-Device-Id': '42' } }),
});
const devices = await hw.devices(); // as with the agent on this computerX-Device-Id— the register number fromGET https://cloud.hw-connector.ru/api/v1/devices(sameX-Api-Key). If the account has one register it may be omitted;X-Device-Machine-Id— the agent installation id (GET /api/v1/system/computer) works instead. The register number comes back in theX-Device-Idresponse header.- A register of another account —
404. The cloud does not passAuthorizationto the agent: the agent calls itself with its own token. - Account registers, who is online, alerts, events, own name and on/off switch of a register — the Cloud API with the same key.
- Cloud commands can be switched off on the register (
hw.cloud.allow-commands: false) — then the agent answers403 COMMANDS_DISABLED.
What is passed
| Methods | GET, POST, PUT, DELETE, PATCH; the query string as is |
|---|---|
| Body | JSON or a file, up to 10 MB (larger — 413) |
| Headers to the agent | Prefer, Accept-Language, Content-Type, Accept, Idempotency-Key (prefixed with cloud:) |
| Response | the agent status and body as is (images and PDF too); headers Content-Type, Location (/api/v1/… → /agent/api/v1/…), Retry-After, Preference-Applied, Content-Disposition |
| Closed | /api/v1/setup/** — 403; paths with .., // — 400 |
| Limit | 600 requests per minute per account, more — 429 and Retry-After |
Waiting and retries
- The cloud waits up to 60 s for the register.
Prefer: wait=Nis passed to the agent but capped at 55 s: if the operation is not done —202andLocation: /agent/api/v1/operations/{id}, ask for the result through the same proxy. WithoutPrefer— as locally. POST,PUT,DELETE,PATCHwithoutIdempotency-Key— the cloud creates apx-…key and returns it in theIdempotency-Keyresponse header (on errors too). After504or502retry with that key — the operation never runs twice.- The register is offline —
503at once: requests are not queued (a print an hour later helps nobody). Guaranteed receipt delivery “when the register shows up” —POST https://cloud.hw-connector.ru/api/v1/receipts(queue, webhook). - Any method, files and headers — agent 2.14.0 and later; older agents take only
GETandPOSTwith JSON through the cloud, the rest —501 AGENT_OUTDATED.
Cloud errors
Cloud answers differ from agent answers by the X-Hw-Proxy-Error header (agent answers never have it); the body is problem+json with the same code.
| HTTP | X-Hw-Proxy-Error | When and what to do |
|---|---|---|
| 401 | UNAUTHORIZED | Missing or wrong X-Api-Key |
| 400 | DEVICE_REQUIRED | The account has several registers and X-Device-Id is missing |
| 400 | BAD_DEVICE_ID | X-Device-Id is not a number |
| 400 | BAD_PATH | A path with “..”, “//” or encoded slashes |
| 404 | DEVICE_NOT_FOUND | The register was not found or belongs to another account |
| 403 | KEY_READ_ONLY | A read-only key: only GET reaches the agent |
| 403 | DEVICE_DISABLED | The register is disabled in the account (PATCH /api/v1/devices/{id}) |
| 403 | SETUP_FORBIDDEN | /api/v1/setup/** is closed through the cloud — setup only on site |
| 405 | METHOD_NOT_ALLOWED | A method other than GET, POST, PUT, DELETE, PATCH |
| 413 | BODY_TOO_LARGE | The body is larger than 10 MB |
| 429 | RATE_LIMITED | The account request limit — wait Retry-After |
| 501 | AGENT_OUTDATED | The agent is older than 2.14.0: only GET and POST with JSON reach it through the cloud |
| 503 | NOT_CONNECTED | The register is not connected to the cloud; Retry-After — when to retry |
| 504 | TIMEOUT | The register did not answer in 60 s — retry with the same Idempotency-Key or ask /operations/{id} |
| 502 | CONNECTION_LOST | The connection dropped mid-request — same as 504 |
| 502 | RELAY_ERROR | Cloud delivery error — same as 504 |