Skip to content

API & Automation

Everything the TravStats web UI does, the REST API can do. Most self-hosters never touch it; some find it the most valuable feature of the lot.

  • Backups via API — fetch all your flights as JSON on a cron, store outside Postgres.
  • AI agents and assistants — let your local Claude / ChatGPT instance read and write your travel history with a scoped token.
  • Dashboards in Home Assistant / Grafana — pull stats endpoints into widgets next to your other home metrics.
  • Bulk corrections — fix a misspelled airline across hundreds of flights in one script run.
  • Mailbox sweepers — walk an IMAP folder, POST every booking confirmation through /parse-email, never type a flight again.
  • Browser plugins — log a flight from any web page that knows the flight number.
  • Migration tooling — read from another tool’s API, write into TravStats.

The API surface mirrors the UI:

ResourceReadWriteEndpoint root
FlightsGET /api/v1/flights, POST /api/v1/flights, PUT /api/v1/flights/:id, DELETE /api/v1/flights/:id
TripsGET /api/v1/trips, POST /api/v1/trips, etc.
BookingsGET /api/v1/trips/bookings, etc.
AirportsGET /api/v1/airports/search?q=…
StatisticsGET /api/v1/stats/summary, …/routes, …/airlines, …/countries
AchievementsGET /api/v1/achievements
ParsersPOST /api/v1/parse-email, POST /api/v1/parse-boardingpass
AuthPOST /api/v1/auth/register, …/login, …/logout
Personal Access TokensGET/POST /api/v1/settings/tokens, DELETE /api/v1/settings/tokens/:id
AdminGET/POST /api/v1/admin/… (admin scope required)

Two complementary references live on the running server:

  • Swagger UI — interactive, click-to-call docs at https://your-instance/api/v1/docs. Auto-generated from the same Zod schemas the API validates against.
  • Raw OpenAPI 3.0 JSON — at https://your-instance/api/v1/openapi.json. Feed it to any OpenAPI-aware tooling: code generators, Postman, Bruno, etc.

Two paths, same credentials:

MechanismSet onUsed for
HttpOnly session cookieBrowser, after POST /auth/loginThe web UI itself
Personal Access TokenAuthorization: Bearer ts_pat_… headerEverything else (scripts, agents, integrations)

Browser sessions stay in the cookie automatically; you don’t see them. For everything programmatic, use a Personal Access Token.

Every endpoint has a rate limit. The defaults are friendly to typical UI use and not so friendly to runaway scripts:

BucketDefault limit
Login attempts5 / 15 min per IP
Flight creation30 / hour per user
Email parser60 / hour per user
Boarding pass parser30 / hour per user
General authenticated reads1000 / hour per user
Admin endpoints100 / hour per user

Personal Access Tokens get their own bucket per tokenpat:<token-id> — so an aggressive script can’t lock the owning user out of the web UI. If you’re hitting limits, either tune them in the source or split your script into multiple tokens.

  • Personal Access Tokens — Mint a token, pick the right scope (read / write / admin), use it from a script. Includes example curl, Python and Node.js snippets.
  • REST API reference — A practical walkthrough of the endpoints you’ll use most: pagination, the (local, timezone) write contract, the merge-on-create flag, the parser endpoints. Pointer to Swagger UI for the rest.