Till King Gateway API

Multi-tenant retail POS gateway — Phase 1 endpoints. All API routes (except device registration) require a JWT Bearer token in the Authorization header.

Device Authentication

POST /gateway/device/register Register a POS device and receive a JWT

Registers (or re-registers) a device with the gateway. No prior auth required. Re-registering the same device_id updates the existing record and issues a fresh token.

{
  "device_id": "unique-device-uuid",
  "device_name": "Till 1 Front",
  "tenant_subdomain": "shop1",
  "branch_id": null
}

201{ token, expires_at, tenant_name, device_id }

POS Operations

POST /v1/sale Submit a POS sale — JWT required

Normalises the client POS payload to ERPNext Sales Invoice format and forwards to the tenant’s ERPNext instance. Items, payments, and customer are mapped using the tenant’s config rules.

{
  "items": [
    { "item_code": "POSHO-5KG", "item_name": "Posho 5kg", "qty": 2, "rate": 24000 }
  ],
  "payments": [
    { "method": "cash", "amount": 30000 },
    { "method": "momo", "amount": 18000, "reference": "MTN-077..." }
  ],
  "customer": "Walk-in Customer",
  "branch_id": 1,
  "till_id": "TILL-01"
}

201{ invoice_id, total, net_total, items, payments }

Offline Sync

POST /sync/batch Upload queued offline transactions — JWT required

Accepts up to 500 transactions per batch. Jobs are enqueued to Redis and processed by background workers with exponential backoff on failure.

{
  "transactions": [
    { "type": "sale", "payload": { ... } },
    { "type": "return", "payload": { ... } }
  ]
}

202{ batch_uuid, job_count, enqueued, redis_ok }

GET /sync/status/{batch_uuid} Check batch sync status — JWT required

Returns the batch status and per-job statuses. Jobs cycle through pending → retrying → synced (or failed after 5 attempts).

200{ batch_uuid, status, summary, jobs[] }

ERPNext Proxy

ANY /erpnext/{path} Forward to tenant ERPNext — tenant subdomain required

Proxies any request to the tenant’s ERPNext API. The tenant is resolved from the Host header (subdomain). The gateway attaches the tenant’s API credentials automatically — the client never sees them.

Example: GET testshop.tillking.com/erpnext/Sales%20Invoice?fields=["name"]

Error Codes

CodeMeaning
401Missing or invalid JWT token
403Device blocked / Tenant suspended
404Tenant not found / Batch not found
422Validation failed — check the errors array in the response
429Rate limit exceeded — see Retry-After header
502ERPNext unreachable — the tenant’s ERPNext instance is down or the URL is wrong

Till King Gateway · ERP Champions Ltd · Kampala, Uganda