Sign in | Sign up

Developer Portal

Train Information

Endpoints for train information, including nearby stations, timetabled and live services.


Nearby stations (1 hit)

Find stations close to a given (lon,lat), ordered by distance.

/uk/train/stations/near[.format]?{lon=&}{lat=}[&page=][&rpp=]

Supported formats: html (default) and json

  • lat and lon define the point around which you want to search;
  • rpp is the number of results per page to return (25 by default, and capped at 25);
  • page is the result page to return (1 by default). rpp and page together are useful for paging through long lists of results.

Example URLs

transportapi.com/v3/uk/train/stations/near.html?lon=-0.102323&lat=51.527789

transportapi.com/v3/uk/train/stations/near.json?lat=51.527789&lon=-0.102323&page=3&rpp=10

Response

Json response format is:

{"minlon","minlat","maxlon","maxlat","searchlon","searchlat",   "page","rpp","total","request_time","stations":
    [
      {"station_code","atcocode","tiploc_code","name","mode",         "longitude","latitude","distance"},
    ...more results...
    ]
}

Where

  • min/max lat/lon is the bounding box of the search
  • search lat/lon is the point used to sort the stations (nearest first)
  • page and rpp are as described above
  • total: the total number of stations within the bounding box
  • request_time: when the request was made
  • stations: an array of stations, sorted by distance from search lat/lon with attributes
  • station_code is the 3-Alpha code for the station. This is a uk-wide coding previously known as 'CRS codes'
  • atcocode: the atcocode for this station, if available
  • tiploc_code: the tiploc_code for this station
  • name: the name of the station
  • mode: the mode of transport
  • longitude/latitude: the station location
  • distance: in metres from search lat/lon

Stations within bounding box (1 hit)

Essentially the same as nearby stations, but the search parameters are specifiying a bounding box, rather than a single point.

/uk/train/stations/bbox[.format]?{minlon=&}{minlat=&}{maxlon=&}{maxlat=}[&page=][&rpp=]

The remaining HTTP parameters have the same meaning as for nearby stations.

Example

transportapi.com/v3/uk/train/stations/bbox.json?minlon=-1.12323&minlat=50.517789&maxlon=-0.092323&maxlat=51.537789&page=3&rpp=8

The json response format is identical to nearby stations.


Stations served by an operator (1 hit)

Retrieves the stations served by any given operator, as identified by their two digit ATOC code.

This function is processing intensive, and may take 10second to repond. You’re encouraged to cache the results, and re-use them in your app.

/uk/train/operator/{atoc_code}/stations[.format]?[rpp=]

  • Supported formats: html (default) and json
  • rpp is the number of results per page to return
    There is no cap on the number of results returned by this method, so feel free to set the limit of results you can fit on one page (the rpp) to a big number.

The json response format is very similar to nearby stations, except there is no information relating to the bounds of a search box, or the distance of stations from a focal point.


Scheduled Station Departures (1 hit)

Timetabled departures from a station.

transportapi.com/v3/uk/train/station/{station_code}/[date]/[time]timetable[.format]?[limit=][&origin=][&destination=][&calling_at=][&called_at=]

  • Supported format: just html (default);
  • station_code is the 3-Alpha Code for the station you are interested in. This is a uk-wide coding previously known as 'CRS codes'. You might discover a particular 3-Apha Code with a call to get nearby stations
  • date an optional date in yyyy-mm-dd format (defaults to today’s date if not specified)
  • time an optional date in hh:mm format (defaults to current time if not specified)
  • limit the maximum number of results to return (capped at the maximum)
  • origin optional filter – only return trains originating from this station (3-Alpha code)
  • destination optional filter – only return trains terminating at this station (3-Alpha code)
  • calling_at optional filter – only return trains that will stop at this station (3-Alpha code)
  • called_at optional filter – only return trains that have stopped at this station (3-Alpha code)

For the origin / destination / calling_at / called_at parameters, if a station cannot be found associated with the 3-Alpha code, it is ignored.

Example URL

transportapi.com/v3/uk/train/station/ZFD/2012-05-01/08:09/timetable


Live Station Departures (1 hit)

Live departures from a station.

transportapi.com/v3/uk/train/station/{station_code}/live[.format]?[limit=]

  • Supported formats: html (default) and json
  • station_code is the 3-Alpha Code for the station you are interested in. This is a uk-wide coding previously known as 'CRS codes'. You might discover a particular 3-Apha Code with a call to get nearby stations
  • limit the maximum number of results to return (capped at the maximum)

Example

transportapi.com/v3/uk/train/station/SYD/live

The JSON response will look like this:

{"station_name":"Sydenham","request_time":"2013-08-06T16:26:31+01:00","station_code":"SYD",
  "departures":{
    "all":[
      {"mode":"train", "service":"24661000", "train_uid":"W73955",
       "origin_name":"London Bridge", "destination_name":"Caterham",
       "platform":"2", "operator":"SN",
       "aimed_departure_time":"16:22", "expected_departure_time":"16:30",
       "best_departure_estimate_mins":3, "aimed_arrival_time":"16:22",
       "expected_arrival_time":"16:30", "best_arrival_estimate_mins":3,
       "status":"LATE", "source":"Network Rail"},
      ...more results...
    ]
  }
}

Where

  • mode - always "train" for this feed
  • service - train service number from timetables, can be used to make a timetable lookup} e.g. https://transportapi.com/v3/uk/train/service/22214000/timetable
  • origin_name - start station for the service
  • destination_name - end station for the service
  • platform - platform, null in some cases where the feed does not provide it
  • operator - train operator code e.g. LO for London Overground
  • aimed_departure_time - timetabled departure e.g. "12:00"
  • expected_departure_time - expected live departure time
  • best_departure_estimate_mins number of minutes until the expected departure (integer)
  • aimed_arrival_time - timetabled arrival time
  • expected_arrival_time - expected live arrival time
  • best_arrival_estimate_mins - number of minutes until the expected live arrival (integer)
  • status - movement status. This can be EARLY, LATE, ON TIME, NO REPORT, ARRIVED
  • source - information source e.g. "Network Rail"

The 'best_departure_estimate_mins/ best_arrival_estimate_mins' value is derived from the live data unless this is absent (no 'expected' values), in which case it is the time to timetabled departure. If this value is a minus number, this is an indication that there have been no further updates on train position: it could be broken down, cancelled or sitting outside the station not triggering an update event. In some cases the 'Status' value may equal "ARRIVED", which can help decode this behaviour. In this case you might want to display 'delayed' or 'due' in the user interface, as appropriate. This value can also be used to work out the request time by differencing the later of the aimed or expected times and the 'best estimate'.

Note that a train showing "No report" close to the departure time may indicate that the train starts at this location.


Live Station Arrivals (1 hit)

Live arrivals at a station.

transportapi.com/v3/uk/train/station/{station_code}/live_arrivals[.format]?[limit=]

Essentially the same as Live Station Departures but with train arrivals information.

The available request parameters and JSON response structure are identical to those of Live Station Departures


Scheduled Service (1 hit)

The next scheduled train service.

transportapi.com/v3/uk/train/service/{service_code}/[station_code]/[date]/[time]/timetable[.format]
* Supported format: just html (default);

  • service_code is the Identifier for this scheduled train service;
  • station_code is the optional 3-Alpha Code for the station you are interested in. It will default to the origin station if not specified. 3-Alpha codes are a uk-wide coding previously known as 'CRS codes'. You might discover a particular 3-Apha Code with a call to get nearby stations
  • date an optional date in yyyy-mm-dd format (defaults to today’s date if not specified);
  • time an optional date in hh:mm format (defaults to current time if not specified).

Example URL

transportapi.com/v3/uk/train/service/22710002/LUT/2012-05-01/08:17/timetable