What is Trafikverkets open API?

Trafikverkets open API is an API to fetch information regarding road and rail traffic.

How do I use Trafikverkets open API?

A valid API key is required. This key can be obtained from the Trafiklab developer portal.

This API has multiple versions, all using the same API key. You should use the latest available endpoint, but can keep using earlier ones if you have an existing application.

1https://api.trafikinfo.trafikverket.se/v2/data.json
1https://api.trafikinfo.trafikverket.se/v2/data.xml

You can use Trafikverkets open API by sending a POST-request, which describes which data you’d like to request, along with optional filters. The data is returned in JSON or XML format, depending on the suffix provided in the request.

A request can look like this:

1<REQUEST>
2  <LOGIN authenticationkey="YourTrafiklabKey" />
3  <QUERY objecttype="SomeObjectType" schemaversion="SomeObjectVersion" limit="10">
4  <FILTER>
5    <EQ name="SomeDataField" value="2" />
6  </FILTER>
7  </QUERY>
8</REQUEST>
If there is no value for a requested field, the field will not be included in the response

The following data types are available:

Data typeDescription
TrainMessageMessages related to works on railroads, technical problems, and similar.
TrainStationStop places, not only for passengers but also for cargo and borders
TrainAnnouncementTimetable information, in other words, information regarding trains at stops or stations. Does not include cargo trains
IconIcons for use on maps or user interfaces
RoadConditionRoad status
RoadConditionOverviewOverview of road status
SituationDescribes actual situations on the road, such as incidents and disturbances of normal traffic. Examples are important information, roadworks, accidents, traffic jams, events, changed ferry times, kolonnkörning (driving behind e.g. snow plows).
WeatherStationReports from roadside weather stations

Coordinates

This API uses the Swedish national coordinate system SWEREF 99 TM. All geometric data is also published in WGS 84. Read more about how to convert SWEREF 99.

Detailed documentation

Complete and updated documentation is available at Trafikverkets website, and contains for instance

  • more information about constructing requests
  • more information about response data structures
  • error messages
  • example code
  • an interactive console for testing

Note that you, as a Trafiklab member, don’t have to register on Trafikverkets website, as you can fetch your API key directly through Trafiklab.

Trafikverkets documentation can be found here: https://api.trafikinfo.trafikverket.se/