All posts by Tim Williams

Lead Developer on the Transport for London Unified API

DevelopersInformation

Change to Absolute URLs in API Responses

On Monday 13th February, we will make a minor change to our Unified API responses so that they will no longer return absolute URLs as references to other API entities. They will now return a relative URL instead.

We don’t anticipate many developers are relying on these URLs being absolute, but if we’re wrong, please let us know as soon as possible in the comments section below or through the API portal.

url-code-screenshot-2

Next Monday we’re making a minor change to our Unified API responses, so that they will no longer return absolute URLs as references to other API entities

Read More

DevelopersInformation

Prudential RideLondon route as Open Data

Prudential RideLondon is a world-class festival of cycling, and the fourth edition will take place this coming weekend – 29-31 July 2016.

We have made the route of the event available as Open Data. You can download it here, and it is free to use under our usual policy. The data in the KML file can be used by developers wishing to incorporate the different sections of the event into their maps or other applications.

For example, the route can be visualised like this, using mapbox and leaflet.js.

Screenshot 2016-07-27 16.33.22.png

The Prudential RideLondon takes place this weekend. Here is the route visualised in leaflet.js

Let us know in the comments if you feel this information is useful for you and the apps you’re developing, and please do let us know if you have any questions on this.

DevelopersNews

Unified API: The Tram Network

Following the addition of the Capital’s tram network to the Tube map for the first time earlier this month, we’ve made some improvements to the trams data in our API. The representation of the Tram network has been merged from four individual lines down to a single line. This makes Trams easier to interpret for customers, and consistent with other rail modes like London Overground.

Screenshot 2016-06-06 15.18.57.png

Use the tram? Add it to your favourites!

Read More

DevelopersInformation

Unified API: Live Tram Arrivals Added

We’ve recently integrated live tram arrivals into our predictions API, and I’ve updated the information on my previous API post Unified API Part 5: AoT – Arrivals of Things to reflect this.

This means that the live trams information is available on our website and through our Unified API, as well as in the many ESUB status boards that are found in stations around London.

We have a total of 408 ESUBs on TfL Rail, Tube and DLR, as well as over 160 on National Rail and 40 on London Overground that are now showing the new trams information.

See Unified API Part 5: AoT – Arrivals of Things in the last section at the end of the post for more details.

DevelopersNews

Run our API examples with Postman

On the development team we constantly test our own API, a task that can become very repetitive. As the Unified API is a REST API, this involves constructing, editing and sending URLs, then examining the JSON responses.

This is possible using just a browser, but can become very tedious and fiddly. There are tools available to help with this and we’ve found they give a massive boost to productivity for this kind of work.

postman-screenshot-2.png

The TfL Unified API in Postman, searching for nearby cycle docking stations.

One tool we use is Postman which streamlines the basics of working with APIs, and adds powerful features for testing, repeatability, and automation. We use it to run tests against our endpoints, and to mock up then flesh out new data feeds.
Read More

DevelopersNews

London Collision Map and Improved Cycle Journey Planning

As part of a wider road safety strategy, last week we launched the London Collision Map and London collision data on our website and in our API, as part of our ongoing commitment to providing open data. We’ve also made improvements to cycle journey planning.

The new cycle journey planning features include:

  • Google street view images at every turn of the route to help cyclists prepare a ‘mental map’ of their route and visualise junctions before they make their journey.
  • The location and details of cycle parking at London rail stations including information on the number of potential spaces, the type of cycle parking and whether it is covered.
  • ‘Cycle route classifications’ for each section of the journey describing the type of cycling environment that cyclists will encounter along their route (e.g. Cycle Superhighways or routes through parks) helping them to be more informed about the journey they will be making.
  • Identification of steep hills along the route.

The other new feature, the London Collision Map, allows searches for road collisions across London, providing information about when and where they occurred, as well as the severity of the incidents, dating back to 2005. It uses STATS-19 casualty dataset, collected annually by the Department for Transport, and shows a significant reduction in the number of collisions over time.

Through this data we’re able to inform people about junctions and roads that have high numbers of collisions, and where road users should be particularly careful. The 2014 figures show that this number fell to its lowest level since records began, in line with the Mayor’s target to halve the number of people killed and seriously injured (KSI’s) by 2020.

The London Collision Map, showing fatal and serious collisions in 2014, around the area of St. James's Park Underground station.

The London Collision Map, showing fatal and serious collisions in 2014, around the area of St. James’s Park Underground station.

Read More

DevelopersInformation

Improved Roads Open Data – Car Parks & JamCams

In my previous post on Roads Open Data I outlined the importance of providing quality data for London’s roads, particularly at a time when our Road Modernisation Plan is being implemented and we are urging drivers to check for disruption before they travel.

We continue to make improvements to our roads open data, with London Underground live car parking spaces availability now available through the Unified API, as well as live video JamCams that give a far better indication of how traffic is flowing in the Capital.

London Underground car parks

London Underground has over 60 car parks with over 11,000 spaces. With the help of our partners NCP and SmartParking, we have released live data showing available spaces for 25 of these car parks. We are seeing whether we can expand the feed to cover all London Underground car parks in the future.

We don’t have this showing on tfl.gov.uk yet, but we’ve made the feed available as open data in the Unified API so that the dev community can have a head start.

You can get the full list of Car Parks from the Places API, which can also be searched by lat/long bounding box or radius. For each car park, we return information such as the address, opening hours, payment methods and facilities, and in some cases, the live occupancy. In the example below, Barkingside Station car park, the OccupancyUrl is returned, indicating that live data is available.

{
  "id": "CarParks_800491",
  "url": "https://api.tfl.gov.uk/Place/CarParks_800491",
  "commonName": "Barkingside Stn (LUL)",
  "placeType": "CarPark",
  "additionalProperties": [
  {
    "category": "Description",
    "key": "NumberOfSpaces",
    "sourceSystemKey": "CarParks",
    "value": "46",
    "modified": "2016-01-07T15:45:43.153"
  },
  {
    "category": "Description",
    "key": "NumberOfDisabledBays",
    "sourceSystemKey": "CarParks",
    "value": "2",
    "modified": "2016-01-07T15:45:43.153"
  },
  {
    "category": "Meta",
    "key": "OccupancyUrl",
    "sourceSystemKey": "CarParks",
    "value": "https://api.tfl.gov.uk/Occupancy/CarPark/CarParks_800491",
    "modified": "2016-01-07T15:45:43.153"
  }...

The URL is based on the place id of the car park, for example “CarParks_800491” so if you know the Car Park id, you can go straight to the occupancy data. We use a separate URL because we have a much shorter time-to-live in our cache for the occupancy vs. the place data (60 seconds and 1 day respectively). In the example below, using Barkingside again, we can see that there’s no spaces available right now.

{
 "id": "CarParks_800491",
 "bays": [
    {
     "bayType": "Disabled",
     "bayCount": 2,
     "free": 0,
     "occupied": 2
    },
    {
     "bayType": "Pay and Display Parking",
     "bayCount": 45,
     "free": 0,
     "occupied": 45
    }
  ],
  "name": "Barkingside Stn (LUL)",
  "carParkDetailsUrl": "https://api.tfl.gov.uk/Place/CarParks_800491"
}

Read More

DevelopersInformation

Unified API Part 5: AoT – Arrivals of Things

In Part 3 of this series, I gave examples of finding the Routes of Things using the Unified API. This article focusses on the “Arrivals of Things” – how to find out when services are going to arrive on those routes.

As before, all of the API examples in this page are live, however they do not include API authentication tokens. This means that if you follow the link as is, you will be using anonymous access, which is throttled for fair use, so you may get a 403 response. We recommend for your own development that you obtain an “app_key” and “app_id” by registering here. The data in these examples will be in JSON format, so installing a JSON formatter plugin in your browser will help you read the data returned.

Ride on time

Let’s start with the most prominent example of arrivals, shown when viewing a nearby stop:

At this bus stop we can see the time-to-stop of the next services due to arrive.

At this bus stop we can see the time-to-stop of the next services that are due to arrive.

Read More

DevelopersInformation

Unified API Part 4: Roads Data

In Part 3 of this series, I gave examples of finding the ‘Routes of Things’ using the Unified API. This post will focus on roads – how to find and make use of the traffic, road disruption and planned works information on London’s road network.

We’re really keen for customers to check for disruption before they travel on all forms of transport, including the capital’s roads. Developers working with our Unified API have a really important role to play in developing products that meet road users’ needs. This is particularly important as we implement our Road Modernisation Plan – £4bn of investment in improving London’s roads – so planning ahead during these works is crucial for businesses and drivers across the city.

This means that the apps developers create will be meeting a genuine need, and we’re keen to make this process as easy as possible by explaining what data is available, how it can be used, and by taking feedback so we can make improvements.

All of the API examples in this page are live, however they do not include API authentication tokens. This means that if you follow the link as is, you will be using anonymous access, which is throttled for fair use, so you may get a 403 response. It is recommended for your own development you obtain an ‘app_key’ and ‘app_id’ by registering here. The data in these examples will be in JSON format, so installing a JSON formatter plugin in your browser will help you read the data returned.

Let’s start with the most prominent example of the roads information, shown when viewing the Traffic status board.

The Traffic Status Board gives info on all TfL managed routes on the London road network

The Traffic Status Board gives info on all TfL managed routes on the London road network

Read More

DevelopersInformation

Unified API Part 3: RoT – Routes of Things

In Part 2 of this series, Dan gave examples of finding the “Locations of Things” using the Unified API. This week, I’ll focus on the “Routes of Things” – the lines, routes and services that join up the locations on the TfL network.

As before, all of the API examples in this page are live, however they do not include API authentication tokens. This means that if you follow the link as is, you will be using anonymous access, which is throttled for fair use, so you may get a 403 response. It is recommended for your own development you obtain an “app_key” and “app_id” by registering here. The data in these examples will be in JSON format, so installing a JSON formatter plugin in your browser will help you read the data returned.

Let’s begin with the most prominent use of routes on the website – the status board. In the Unified API a line is the top-level entity which groups the routes of a service together. The Line endpoint allows us to request all of the lines for a given set of modes, so is a useful starting point for navigating into the available routes. Showing the status of a line is such a common use case that the endpoint also includes an option to include the service status for each line by appending /Status to the URL:

https://api.tfl.gov.uk/Line/Mode/tube,dlr,overground,tflrail/Status

rot_status

The status board requests the Tube, DLR, Overground and TfL Rail line status. A line can represent multiple routes around the TfL network.

Read More