10 Västtrafik API
b25marem edited this page 2026-05-28 07:44:21 +00:00

How to acquire API tokens

To gain access to Västtrafiks public API's a Västtrafik developer account is necessary, which can be created here. This allows for the creation of applications, which can subscribe to the available API's. Note: the applications have access to API's, not the account.

Creation of an account also creates a unique client identifier, secret and an authentication key. Each application has to fetch an access token to API's using the authentication key.

Duration of validity

It nowhere states the duration of which a developer account and its applications are valid, which leads me to think that they are valid indefinitely, unless the applications connected to a developer account breaks the restrictions, at which point Västtrafik has the right to delete the offending account. Västtrafik also has the right to stop support of any and all API's at any given time.

The client identifier, secret and an authentication key are bound to the account and therefore follow the above.

Access tokens are valid for 24 hours.

Restrictions

All Västtrafik API's follow the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication license, which can be read here.

Västtrafik also have their own terms of use, which can be read here.

Fetching data

The frontend fetches data through:

/api/vasttrafik/departures
/api/vasttrafik/arrivals

The backend service:

  1. Requests an OAuth token
  2. Calls the Västtrafik external API
  3. Parses the JSON response
  4. Extracts simplified traffic data
  5. Returns the simplified data to the frontend

The service uses a shared HttpClient instance for all requests. The current implementation fetches live traffic data directly from the external API and does not store traffic data in the database.

API documentation: https://developer.vasttrafik.se/apis/13/v4

Data received

The backend returns a simplified JSON structure.

Example response:

[
  {
    "time": "2026-05-28T12:30:00Z",
    "line": "1",
    "direction": "Skultorp"
  }
]

Returned fields: time line direction