Web REST API Specification
Diátaxis Type: Reference & Specification | Status: Canonical | Owner: Platform Engineering | Review: Continuous
The Bio-Quant TWA Gateway (diabetic.telegram_bot.twa_api) exposes REST endpoints for Telegram Mini App (TWA) HUD interfaces and Nightscout-compatible CGM ingress on Port 8000.
1. Authentication Protocols
The gateway supports three fail-closed authentication mechanisms:
- Telegram Mini App initData (
Authorization: tma <initData>): Validates Telegram HMAC-SHA256 signatures againstTELEGRAM_BOT_TOKEN. - Nightscout SHA-1 Secret (
api-secretheader or?secret=<token>): Header- or query-based raw secret or SHA-1 hash matchingAPI_SECRETor the tenant's device secret hash. - Development Token (
Authorization: dev <token>): Optional loopback/browser testing token matchingTWA_DEV_TOKEN.
2. Ingress & Telemetry Endpoints
POST /api/v1/entries and POST /t/{slug}/api/v1/entries
Ingests continuous glucose readings from xDrip+, Ottai, or Nightscout uploader clients.
- Authentication: Required (
api-secretheader, query?secret=..., or TMA session). - Request Body: Single object or array of objects:
- Response
200 OK:{"status": "ok", "tenant": "default", "inserted": 1}
GET /api/v1/entries and GET /t/{slug}/api/v1/entries
Retrieves recent readings in reverse chronological order.
- Authentication: Required.
- Query Parameters:
count(int, default 10): Number of entries to retrieve.- Response
200 OK: Array of Nightscout SGV entries.
3. HUD & Configuration Endpoints
GET /api/v1/hud and GET /t/{slug}/api/v1/hud
Retrieves instantaneous HUD state and forecast horizons.
- Response
200 OK:
GET /api/v1/client/cgm_config and GET /t/{slug}/api/v1/client/cgm_config
Retrieves pre-computed client connection parameters for xDrip+/Nightscout configuration.
- Authentication: Required (
require_twa_user). - Response
200 OK:
GET /healthz and GET /readyz
Health check and readiness probes for container runtime monitoring.
- Response
200 OK:{"status": "healthy"}/{"status": "ready"}