API cheat-sheet

← back to calendar

Authentication

Every request under /api/ (except POST /api/login) needs a logged-in user. Scripts and chat sessions use an API token: create one on the Account page (it is shown once) and send it on every request as Authorization: Bearer <token>. A token acts as its owner and only ever sees and changes that user's own sports and entries; revoke it there any time. The browser UI uses a session cookie from POST /api/login instead.

MethodPathPurpose
POST/api/login, /api/logoutbrowser session: {"username","password"}
GET/PUT/api/mecurrent user and the users sharing with you / update display_name
GET/PUT/api/me/sharesthe users who may view your training / replace that list: {"usernames":["anna","bob"]}
GET/api/me/shares/suggest?q=usernames starting with q (for autocomplete)
POST/api/me/passwordchange your password (browser session only)
GET/POST/DELETE/api/tokens[/{id}]list / create / revoke API tokens (browser session only)
GET/PUT/DELETE/api/aiAI chat settings: provider (anthropic, openai, or the key-less test provider echo), model, API key (never returned) (browser session only)
POST/api/ai/modelslist a provider's models for a key (browser session only)
GET/POST/PUT/DELETE/api/ai/memory[/{id}]the chat's memory notes (browser session only)
GET/PUT/api/admin/settingsadmin only (the admin_user from config.ini, browser session; like /admin.html): the AI coach instructions, {"coach_prompt": "..."}; empty resets to the default
POST/api/chatAI chat turn: {"messages":[{"role","content"}]} returns reply and proposals to apply through the entries/memory routes (browser session only)

Every GET below also accepts ?user_id=<id> to read the data of another user who has opted in to sharing (see /api/me); writes always go to your own data.

Sports, fields & derived fields

Sports (formerly a fixed running/swimming/biking/gymnastics/ wellbeing enum) are now fully admin-managed via config.html or the API. Each sport has a name, a hex color, and its own set of fields — each with a unit that picks how it's stored/validated:

unitStorageNotes
m, km, countplain numbere.g. distance, reps. m and km share one base unit: stored in meters, km is only the field's display unit (API values are kilometers for a km field). A field can be switched between the two; derived fields compute on meters (0.001 * a = km).
timewhole secondsUI takes minutes+seconds, API takes total seconds
stringtextsingle-line Unicode, like comment

A sport can also define derived_fields: name = alpha * field_a <op> beta * field_b, where op is one of multiply/divide/diff/sum. These are never stored — always computed on read from the two source fields' current values, skipping entries missing either one. Every entry returned by the API carries them in a read-only derived object, {derived_field_id: number} (like values); a derived field is omitted when an input is missing or the result is undefined (division by zero).

MethodPathPurpose
GET/api/metaapp/version info, active sports (incl. their fields/derived fields)
GET/api/sportslist all sports (incl. inactive)
POST/api/sportscreate a sport
GET/PUT/DELETE/api/sports/{id}fetch/update/delete a sport (private: true hides it from users you share with)
GET/POST/api/sports/{id}/fieldslist/add a sport's fields
PUT/DELETE/api/fields/{id}update/delete a field
GET/POST/api/sports/{id}/derived-fieldslist/add a sport's derived fields
PUT/DELETE/api/derived-fields/{id}update/delete a derived field
GET/api/entrieslist entries (filters below)
POST/api/entriescreate an entry
GET/api/entries/{id}fetch one entry, incl. its field values
PUT/api/entries/{id}update an entry (partial updates OK)
DELETE/api/entries/{id}delete an entry
GET/api/planalias for /api/entries?is_plan=1
GET/api/export?format=json|csv&sport_id=…download entries (json, or csv - dynamic columns if sport_id given)

Filters for GET /api/entries and /api/export (all optional, combinable): from=YYYY-MM-DD, to=YYYY-MM-DD, sport_id=<id>, is_plan=0|1.

Entry fields

FieldTypeNotes
datestringYYYY-MM-DD, required on create
sport_idnumbermust reference an existing sport, required
commentstringUnicode text (line breaks allowed, other control characters not), max 500 characters, may be null
is_planbooleantrue = proposed/planned, false = actually performed
valuesobject{field_id: value}; a field's value type follows its unit (see table above); null clears it

Example: log a run

curl -H 'Authorization: Bearer TOKEN' -X POST https://YOUR-DOMAIN/api/entries \
  -H 'Content-Type: application/json' \
  -d '{"date":"2026-09-20","sport_id":1,
       "comment":"easy long run, felt good","is_plan":false,
       "values":{"1":10,"2":3150}}'

(assuming sport id 1 = Running, field id 1 = Distance (km), field id 2 = Duration (time, seconds) - fetch /api/meta to look up the current ids.)

Example: rewrite the plan for a week

Fetch what's currently planned, then PUT/POST/DELETE as needed:

curl -H 'Authorization: Bearer TOKEN' "https://YOUR-DOMAIN/api/plan?from=2026-09-15&to=2026-09-21"

Errors

Validation failures return HTTP 400 with {"error": "..."}; a missing or invalid login returns 401 (too many failed logins: 429); someone else's id returns 404; deleting a sport/field that still has recorded data returns 409 (deactivate it instead); everything else follows normal HTTP status codes.