HW agent API 2.14.1

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.json
JavaScript
// 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 computer
  • X-Device-Id — the register number from GET https://cloud.hw-connector.ru/api/v1/devices (same X-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 the X-Device-Id response header.
  • A register of another account — 404. The cloud does not pass Authorization to the agent: the agent calls itself with its own token.
  • Cloud commands can be switched off on the register (hw.cloud.allow-commands: false) — then the agent answers 403 COMMANDS_DISABLED.

What is passed

MethodsGET, POST, PUT, DELETE, PATCH; the query string as is
BodyJSON or a file, up to 10 MB (larger — 413)
Headers to the agentPrefer, Accept-Language, Content-Type, Accept, Idempotency-Key (prefixed with cloud:)
Responsethe 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
Limit600 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=N is passed to the agent but capped at 55 s: if the operation is not done — 202 and Location: /agent/api/v1/operations/{id}, ask for the result through the same proxy. Without Prefer — as locally.
  • POST, PUT, DELETE, PATCH without Idempotency-Key — the cloud creates a px-… key and returns it in the Idempotency-Key response header (on errors too). After 504 or 502 retry with that key — the operation never runs twice.
  • The register is offline — 503 at 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 GET and POST with 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.

HTTPX-Hw-Proxy-ErrorWhen and what to do
401UNAUTHORIZEDMissing or wrong X-Api-Key
400DEVICE_REQUIREDThe account has several registers and X-Device-Id is missing
400BAD_DEVICE_IDX-Device-Id is not a number
400BAD_PATHA path with “..”, “//” or encoded slashes
404DEVICE_NOT_FOUNDThe register was not found or belongs to another account
403SETUP_FORBIDDEN/api/v1/setup/** is closed through the cloud — setup only on site
405METHOD_NOT_ALLOWEDA method other than GET, POST, PUT, DELETE, PATCH
413BODY_TOO_LARGEThe body is larger than 10 MB
429RATE_LIMITEDThe account request limit — wait Retry-After
501AGENT_OUTDATEDThe agent is older than 2.14.0: only GET and POST with JSON reach it through the cloud
503NOT_CONNECTEDThe register is not connected to the cloud; Retry-After — when to retry
504TIMEOUTThe register did not answer in 60 s — retry with the same Idempotency-Key or ask /operations/{id}
502CONNECTION_LOSTThe connection dropped mid-request — same as 504
502RELAY_ERRORCloud delivery error — same as 504