Trafik Proxy API documentation

  1. Stations
  2. Messages
  3. Reason Codes
  4. Delayed Trains
  5. Delayed Trains with live position

Stations

A station has the following attributes:

LocationSignature
AdvertisedLocationName
Geometry.WGS84
PlatformLine

To get all stations:

GET /stations

Result:

{
  "data": [
    {
      "AdvertisedLocationName": "Astrid Lindgrens värld",
      "Geometry": {
        "WGS84": "POINT (15.840063951305682 57.67270729523255)"
      },
      "LocationSignature": "Alv",
      "PlatformLine": [
        "1"
      ]
    },
    {
      "AdvertisedLocationName": "Aneby",
      "Geometry": {
        "WGS84": "POINT (14.81189626871035 57.837434576066045)"
      },
      "LocationSignature": "Any",
      "PlatformLine": [
        "1",
        "2"
      ]
    },
    {
      "AdvertisedLocationName": "Aspen",
      "Geometry": {
        "WGS84": "POINT (12.240512241673448 57.75442205677955)"
      },
      "LocationSignature": "Apn",
      "PlatformLine": [
        "1",
        "2"
      ]
    },
....

Messages

A message has the following attributes:

EventId
EndDateTime
Geometry.WGS84
ExternalDescription
StartDateTime
LastUpdateDateTime
ReasonCode
TrafficImpact
Header

To get all messages:

GET /messages

Result:

{
  "data": [
    {
      "ExternalDescription": "Trafikverket bygger ut Mälarbanan mellan Sundbyberg och Jakobsberg söndagar kl. 02.00 - 08:20. SL pendeltåg ersätts med buss och tunnelbana.\nInställda avgångar och förlängd restid förekommer.\nFör mer information om din resa, kontakta ditt tågbolag.\n",
      "Geometry": {
        "WGS84": "POINT (17.9025365385664 59.3923400986982)"
      },
      "EventId": "2666822",
      "Header": "Banarbete",
      "ReasonCode": [
        {
          "Code": "IBT",
          "Description": "banarbete"
        }
      ],
      "TrafficImpact": [
        {
          "IsConfirmed": true,
          "FromLocation": [
            "Bål"
          ],
          "AffectedLocation": [
            "Bkb",
            "Brny",
            "Bro",
            "Duo",
            "Huv",
            "Jkb",
            "Khä",
            "Kän",
            "Sod",
            "Spå",
            "Sub",
            "Tmö",
            "Tot"
          ],
          "ToLocation": [
            "Sci"
          ]
        },
        {
          "IsConfirmed": true,
          "FromLocation": [
            "Sub"
          ],
          "AffectedLocation": [
            "Bkb",
            "Duo",
            "Spå"
          ],
          "ToLocation": [
            "Jkb"
          ]
        }
      ],
      "StartDateTime": "2018-12-15T02:00:00.000+01:00",
      "LastUpdateDateTime": "2021-01-21T08:46:30.150+01:00"
    },
....

Reason Codes

A reason code has the following attributes:

Code
GroupDescription
Level1Description
Level2Description
Level3Description

To get all reason codes:

GET /codes

Result:

{
  "data": [
    {
      "Code": "ANA002",
      "GroupDescription": "Annonseringstexter",
      "Level1Description": "Avvikelse",
      "Level2Description": "Nationell",
      "Level3Description": "Bakre tåg"
    },
    {
      "Code": "ANA004",
      "GroupDescription": "Annonseringstexter",
      "Level1Description": "Avvikelse",
      "Level2Description": "Nationell",
      "Level3Description": "Brofel"
    },
    {
      "Code": "ANA003",
      "GroupDescription": "Annonseringstexter",
      "Level1Description": "Avvikelse",
      "Level2Description": "Nationell",
      "Level3Description": "Banarbete"
    },
    {
      "Code": "ANA005",
      "GroupDescription": "Annonseringstexter",
      "Level1Description": "Avvikelse",
      "Level2Description": "Nationell",
      "Level3Description": "Broöppning"
    },
....

Delayed Trains

All delayed trains in Sweden for the coming 14 hours is shown.

A delayed train has the following attributes:

ActivityId
ActivityType
AdvertisedTimeAtLocation
EstimatedTimeAtLocation
AdvertisedTrainIdent
OperationalTrainNumber
Canceled
FromLocation
ToLocation
LocationSignature
TimeAtLocation
TrainOwner

To get all delayed trains:

GET /delayed

Result:

{
  "data": [
  {
    "ActivityId": "1500adde-f75d-c409-08dc-3e613d7638c5",
    "ActivityType": "Avgang",
    "AdvertisedTimeAtLocation": "2024-03-22T08:15:00.000+01:00",
    "AdvertisedTrainIdent": "11316",
    "Canceled": false,
    "EstimatedTimeAtLocation": "2024-03-22T08:34:00.000+01:00",
    "FromLocation": [
      {
        "LocationName": "Hie",
        "Priority": 1,
        "Order": 0
      }
    ],
    "LocationSignature": "Hbgb",
    "OperationalTrainNumber": "11316",
    "ToLocation": [
      {
        "LocationName": "Hb",
        "Priority": 1,
        "Order": 0
      }
    ],
    "TrainOwner": "Ö-TÅG"
  },
  {
    "ActivityId": "1500adde-f75d-c409-08dc-3e6165572e33",
    "ActivityType": "Avgang",
    "AdvertisedTimeAtLocation": "2024-03-22T08:15:00.000+01:00",
    "AdvertisedTrainIdent": "1707",
    "Canceled": false,
    "EstimatedTimeAtLocation": "2024-03-22T08:33:00.000+01:00",
    "FromLocation": [
      {
        "LocationName": "Hb",
        "Priority": 1,
        "Order": 0
      }
    ],
    "LocationSignature": "Ög",
    "OperationalTrainNumber": "1707",
    "ToLocation": [
      {
        "LocationName": "Trg",
        "Priority": 1,
        "Order": 0
      }
    ],
    "TrainOwner": "SKANE"
  },
....

Delayed Trains with live position

Connect to socket at https://trafik.emilfolino.se.

Train positions for delayed train are delivered in the following format.

{
    train: '28918',
    position: [ 59.64232211660103, 12.676806451022097 ]
}

Code example with socket.io-client

const socket = io("https://trafik.emilfolino");

socket.on("position", (data) => {
    console.log(data); // logs { train: '28918', position: [ 59.64232211660103, 12.676806451022097 ] }
});