Skip to content

API ​

runsten-api serves a JSON API under /api/v1, for the web interface and for your scripts: it reads the vehicles and their events, and writes the account's settings and the costs of charges.

The API is described by an OpenAPI 3.1 document, api/openapi.yaml: routes, parameters, schemas, error codes, and what the fields mean. Clients can generate their types from it, for instance with npx openapi-typescript api/openapi.yaml -o api.ts.

Signing in ​

Every route requires a session: sign in with POST /api/v1/session, which sets the session cookie, and send the cookie back.

sh
curl -c jar -H 'Content-Type: application/json' \
  -d '{"username":"admin","password":"…"}' http://127.0.0.1:8081/api/v1/session
curl -b jar http://127.0.0.1:8081/api/v1/vehicles

A program can send a personal access token instead, created in the settings under API access: Authorization: Bearer rst_…. A token reads what the session reads, but the session's and the tokens' routes, at most 120 requests at once then 2 per second. It changes nothing, unless it was created with May mark the trips' purpose (the scope trips:mark), which allows PUT /api/v1/vehicles/{id}/trip-marks alone; a token created with May receive notifications (the scope notifications) registers its device, its Live Activities and sets the notification preferences (PUT, DELETE /api/v1/devices/{id}, PUT /api/v1/devices/{id}/live-activity-token, PUT /api/v1/devices/{id}/live-activities/{vehicle}, PUT /api/v1/notification-preferences); any other write answers 403 insufficient_scope.

sh
curl -H 'Authorization: Bearer rst_…' http://127.0.0.1:8081/api/v1/vehicles

A request body is sent as application/json, but the files of an import, as multipart/form-data.

Routes ​

Route
GET, POST, DELETE /api/v1/sessionthe current session; sign in; sign out
GET /api/v1/vehicles, …/vehicles/{id}the vehicles, their model, their sheet (colour, specifications, the name a Tesla's owner gave it), the state of their connection (Volvo, Polestar or Tesla) and what the collector did on its latest pass
GET /api/v1/vehicles/{id}/picturethe vehicle's picture, relayed from its maker (a Volvo's) or read by the collector and stored (a BMW's), when its sheet.picture is true
GET /api/v1/vehicles/{id}/variantsthe catalog's variants of the vehicle's family (of its brand, for a Polestar of the Data Portal), the candidates of the recognition first
PUT /api/v1/vehicles/{id}/modelchoose the variant and the onboard charger (null for the recognition, and for a charger not stated)
GET /api/v1/vehicles/{id}/statethe latest known values: SoC, range, odometer, position, charging, each with when it was read
GET /api/v1/vehicles/{id}/trips, …/chargesnewest first, by pages (limit, cursor), within a period (from, to)
GET /api/v1/vehicles/{id}/trips/{trip}, …/charges/{charge}one trip or charge
GET /api/v1/vehicles/{id}/trips.csv, …/charges.csvthe trips or charges of a period (from, to; the charges of a place) as a CSV file, oldest first
GET /api/v1/vehicles/{id}/readings.csvevery value the vehicle reported within a period (from, to, both required, a month at most) as a CSV file, one row per value: fetched_at, source, endpoint, field, value (Exporting your data)
GET /api/v1/vehicles/{id}/chargingthe charge in progress, null when none: what it added so far, its power, its cost so far, and read_at, its latest reading; not an event of the list, which has it under the same id once over
GET /api/v1/vehicles/{id}/trips/{trip}/trackthe track of an imported trip, a GeoJSON LineString; 404 for a trip without one
PUT, DELETE /api/v1/vehicles/{id}/charges/{charge}/costenter what a charge cost; delete it
GET /api/v1/vehicles/{id}/imports, DELETE …/imports/{source}the trips and charges imported from other apps, by source; delete one source's
POST /api/v1/vehicles/{id}/aximote-vehiclesthe vehicles of an Aximote account, the token in the body; the one with the vehicle's VIN marked
POST, GET /api/v1/vehicles/{id}/import-jobimport the vehicle's history from Aximote, in the background (202, 409 while one runs); its progress and report
POST /api/v1/vehicles/{id}/imports/volvo_data_portalimport the files of the Volvo Data Portal, at once: a multipart/form-data body with the trips file and, optionally, the waypoints file (32 MiB at most); the report
POST /api/v1/vehicles/{id}/imports/aaos_loggingimport the export of AAOS Logging, at once: a multipart/form-data body with the export file, the ZIP Google Drive gives for the car's folder (512 MiB at most); the report
GET /api/v1/vehicles/{id}/statstotals of a period (from, to) and the odometer at its ends, by day, week or month in a time zone (bucket, tz)
GET /api/v1/vehicles/{id}/parkedthe stops of a period (from, to), newest first: the parked intervals behind the statistics' loss while parked, each with its time, its loss, its power, its time asleep, its temperature and the events around it
GET /api/v1/vehicles/{id}/batterythe estimated battery capacity over the whole history
GET, PUT /api/v1/settingsthe account's currency, and the accepted ones
GET, POST /api/v1/placesthe places, with their tariffs; create one
GET, PUT, DELETE /api/v1/places/{place}one place; replace it whole, tariff included; delete it
GET /api/v1/places/{place}/unpricedthe place's charges that started before its tariff's first day
GET /api/v1/instancethe release the instance runs and a newer one, its map tiles (map_tiles: the tiles' url and their attribution, null when the instance has no maps, see Maps), and whether it sends push notifications (notifications)
PUT, DELETE /api/v1/devices/{id}register the device an app runs on, its ID drawn by the app (platform apns or fcm, its push token, locale, app_version); remove it
PUT /api/v1/devices/{id}/live-activity-tokenthe token the device's push service starts a charge's Live Activity with (iOS's push-to-start token); null: none is started
PUT /api/v1/devices/{id}/live-activities/{vehicle}the Live Activity the device shows of the vehicle's charge in progress (charge, its push token, null once dismissed): the instance updates it at each new reading, at least 50 seconds apart, and ends it once the charge is over; only figures go out. The kind charge_live_activity of the notification preferences turns them off for a vehicle. Revoking the access token a device registered with removes the device
GET, PUT /api/v1/notification-preferenceswhat the user is told of: the account's kinds, a default for every vehicle, each vehicle's own choice (on, off, default); a PUT sets the kinds it lists, and leaves the others
GET /api/v1/charge-costs/orphansthe entered costs that no charge takes any more
PUT /api/v1/charge-costs/orphans/{cost}/charge, DELETE …/orphans/{cost}attach one to a charge; delete it

Conventions ​

  • Units are in the field names: _km, _m, _kwh, _pct, _w, _kw, _s; _minor in minor units of the account's currency (cents), price_per_kwh in its major units.
  • Times are RFC 3339 in UTC. Trip and charge times are bounds: start.after, start.before, end.after, end.before. reconstructed marks the events that were never seen.
  • Imported events come in the same lists as the derived ones, with imported: true: trips and charges another app (Aximote, the Volvo Cars app) or Volvo Cars' Data Portal cut from its own readings, before Runsten read the vehicle. Their times are exact (after equals before), and their ID is their source and their ID there, aximote:8812. sources tells where every event comes from: the sources of a derived event's readings (volvo), or the app of an imported one.
  • Unknown is null, never zero.
  • Energies are estimates: ΔSoC × capacity_kwh, with capacity_source catalog_net (the net capacity of the variant) or api (the capacity the car reports, a Volvo's).
  • Durations are {"min", "max"} in seconds.
  • A cost is {"currency", "min_minor", "max_minor", "source", …}, min_minor = max_minor when it is one amount; source is tariff, entered, or imported (what the app of an imported charge says it cost, in the account's currency).
  • Statistics count each event once, in the interval that holds its start.after; a sum's _unknown companion counts the events that lacked a value. At most 400 intervals; tz is an IANA time zone, UTC by default.
  • Errors are {"error": {"code": …, "message": …}}.