Developer Reference

REST API Reference

Full reference for the Online Snooker Scoring platform API. All endpoints return application/json. State changes are persisted automatically — no separate save call is required.

Base URL

All paths are relative to your deployment root, e.g. https://yourdomain.com

Content Type

Send Content-Type: application/json on all POST/PUT requests.

Errors

Errors return {"error": "description"} with an appropriate HTTP status code.

Club from Auth

Club context is derived automatically from your API key or manager session — never pass club_id in requests.

Authentication

API Key
How to authenticate Protected endpoints require either an active manager session (browser cookie) or a club API key. Pass the key using any of the following methods:

Authorization: Bearer sk_<your-key> header
X-Api-Key: sk_<your-key> header
?api_key=sk_<your-key> query parameter

Generate keys from the /club settings page or via the key management endpoints below. Raw keys are shown only once at creation time.

API Key Management

Manager Session
GET /api/club/api-keys List API keys for your club

Returns all API keys for the club (active and revoked). Raw key values are never returned — only the prefix and metadata. Requires manager session for the same club.

Response
[
  {
    "id": 1,
    "label": "TV Display Screen",
    "key_prefix": "sk_ABCD",
    "is_active": true,
    "last_used_at": "2026-04-17T10:22:00",
    "created_at": "2026-04-01T09:00:00"
  }
]
POST /api/club/api-keys Generate a new API key

Creates a new API key for the club. The full raw key is returned once only — store it securely. Subsequent calls to list keys will only show the prefix.

FieldTypeNotes
labelstringrequired — human-readable name, e.g. "TV Display"
Response (201)
{
  "success": true,
  "id": 1,
  "key": "sk_AbCdEfGhIjKlMnOpQrStUvWxYz012345",
  "key_prefix": "sk_AbCdEf"
}
DELETE /api/club/api-keys/{key_id} Revoke an API key

Marks the key as inactive. Any requests using the revoked key will immediately receive 401. Requires manager session for the same club.

Response
{ "success": true }

Live Game State & Scoreboard Remote Control

API Key or Manager
GET /api/state/{table_id} Get current live state for a table

Returns the current scoring state for the given table. Requires manager session or API key — club is identified automatically from auth.

Response (abridged)
{
  "players": [{"name": "Alice", "club": "TRSCL", "nationality": "GB"}, {...}],
  "player_ids": [3, 7],
  "current_player": 0,
  "frames_won": [2, 1],
  "current_frame": {
    "points": [47, 12],
    "current_break": 23,
    "reds_remaining": 8
  },
  "game_mode": "frames",
  "current_match_id": 42
}
GET /api/game_stats/{table_id} Full internal game state for a table

Returns the raw internal game-state dict for the given table. Includes undo history, frame stats, and all internal counters. Club is identified from auth. Use /api/state/{table_id} for the leaner client-formatted state.

POST /api/add_ball Score a ball for the current player

Adds points to the current player's break. Returns the updated game state.

FieldTypeNotes
table_idstringrequired
pointsintrequired — ball value (1–7)
ballstringoptional — e.g. "red", "black", "manual"
POST /api/foul Register a foul

Awards foul points to the non-offending player.

FieldTypeNotes
table_idstringrequired
foul_pointsintoptional — minimum 4, default 4
POST /api/switch_player Switch the active player

Ends the current player's visit and transfers play to the other player.

FieldTypeNotes
table_idstringrequired
POST /api/undo Undo the last action

Steps back one entry in the undo history. Returns 400 if nothing to undo.

FieldTypeNotes
table_idstringrequired
POST /api/end_frame End the current frame

Finalises the current frame, records the winner, and starts a new frame. If the match target is reached the match is completed and persisted.

FieldTypeNotes
table_idstringrequired
POST /api/reset Reset the table to idle

Clears all live state for the table. Any in-progress match is finalised and closed in the database.

FieldTypeNotes
table_idstringrequired
POST /api/set_player_info Assign players to a table

Sets player names, clubs, nationalities and optionally links to database player records. Call before the first frame is scored. A match record is created lazily when the first frame ends.

FieldTypeNotes
table_idstringrequired
player1_namestringoptional
player1_idintoptional — DB player ID; auto-fills name & nationality
player1_nationalitystringoptional — ISO 3166-1 alpha-2
player2_namestringoptional
player2_idintoptional
player2_nationalitystringoptional
game_modestringoptional — e.g. "(5)" for best of 5

Players

API Key or Manager
GET /api/players List players for a club
ParamTypeNotes
include_inactivebooloptional — include inactive players, default false
Response
[
  { "id": 3, "name": "Alice", "nationality": "GB", "is_active": true, "sort_order": 0 }
]
POST /api/players Create a player
FieldTypeNotes
namestringrequired
nationalitystringoptional
is_activebooloptional — default true
PUT /api/players/{player_id} Update a player

Partial update — only provided fields are changed.

FieldTypeNotes
namestringoptional
nationalitystringoptional
is_activebooloptional
sort_orderintoptional
DELETE /api/players/{player_id} Delete a player

Permanently removes the player record. Returns 404 if not found.

POST /api/players/reorder Reorder players

Sets the display order for a list of players in bulk.

FieldTypeNotes
orderint[]required — array of player IDs in desired order

Live Tables

API Key or Manager
GET /api/live/tables Get all table states for a club

Returns the live status of every active table. The primary endpoint for public display screens. Club is identified from auth.

Response
{
  "club_id": 5,
  "club_name": "TRSCL",
  "session_high_break": 63,
  "tables": [
    {
      "scoreboard_id": 1,
      "table_name": "Table 1",
      "status": "live",
      "player1": { "name": "Alice", "frames": 2, "points": 47 },
      "player2": { "name": "Bob",   "frames": 1, "points": 12 },
      "match_start": "2026-04-17T09:12:00"
    },
    {
      "scoreboard_id": 2,
      "table_name": "Table 2",
      "status": "idle"
    }
  ]
}
GET /api/stats/matches Player match stats

Returns all recorded matches for a player, with frame wins/losses and high breaks. Matches with no completed frames are excluded.

ParamTypeNotes
player_idintrequired
fromdateoptionalYYYY-MM-DD
todateoptionalYYYY-MM-DD
GET /api/history/matches Recent match history

Returns the most recent completed matches for a club, newest first. Club is identified from auth.

ParamTypeNotes
limitintoptional — max 100, default 25
GET /api/match/{match_id} Full match detail

Returns complete frame-by-frame detail for a single match including player names, points per frame, breaks, and high breaks.

Tournaments

API Key or Manager
GET /api/tournaments List tournaments for a club

Returns all tournaments for the club identified from auth.

GET /api/tournaments/{tournament_id}/results Full tournament results

Returns the full bracket/group results for a tournament. Used by the public results wall display.

GET /api/tournaments/{tournament_id}/high-breaks Tournament high breaks

Returns the highest breaks achieved during a tournament, sorted descending. Used by the high breaks display screen.

Health Check

Public
GET /health Application health status

Returns 200 with DB and Redis status when healthy, 500 on error. Use for uptime monitoring.

Response
{ "status": "healthy", "db": "ok", "redis": "ok" }