Artisan IMG > Transport for London (TFL) (transport-for-london-tfl) (185f02fb-891d-48a7-99f2-bea2f42b3abe)
Transport For London (TFL)
Artisan IMG > Transport for London (TFL) (transport-for-london-tfl) (185f02fb-891d-48a7-99f2-bea2f42b3abe)

Transport For London (TFL)
1.0

Information on all forms of transport in London.

Overview
Copy

Transport for London is a service connector. It brings together data across all modes of transport into a single source of information and provides access to the most highly requested realtime and status information across all the modes of transport, in a single and consistent way.

Authentication
Copy

When using the Transport for London connector, the first thing you will need to do is go to your Tray.io account page, and select the workflow you wish to work on. Once in the workflow builder itself, search and drag the TFL connector from the connectors panel (on the left hand side) onto your workflow.

With the new TFL connector step highlighted, in the properties panel on the right, click on 'New Authentication' which is located under the 'Settings' heading.

This will result in a Tray.io authentication pop-up window. The first page will ask you to name your authentication, and state which type of authentication you wish to create ('Personal' or 'Organisational').

As you can see, the next page asks you for your an 'API Key' and 'API ID' as credentials.

To obtain an API key to authenticate to TFL, you will need to request a new API key by emailing developers@tfl.gov.uk.

Once you have added these fields to your Tray.io authentication popup window, click on the 'Create authentication' button. Go back to your settings authentication field (within the workflow builder properties panel), and select the recently added authentication from the dropdown options now available.

Your connector authentication setup should now be complete.

Available Operations
Copy

The examples below show one or two of the available connector operations in use.

Please see the Full Operations Reference at the end of this page for details on all available operations for this connector.

Example Usage
Copy

TRAY POTENTIAL: Tray.io is extremely flexible. By design there is no fixed way of working with it - you can pull whatever data you need from other services and work with it using our core and helper connectors. This demo which follows shows only one possible way of working with Tray.io and the Transport for London connector. Once you've finished working through this example please see our Introduction to working with data and jsonpaths page and Data Guide for more details.

Below is an example of a way in which you could potentially use the Transport For London connector, to retrieve the line statuses by a given mode.

The steps will be as follows:

  1. Setup using a manual trigger and retrieve a list of lines by mode

  2. Loop through this list of lines

  3. Retrieve the line status of each loop

The final outcome should look like this:

1 - Setup Trigger and List Lines by Mode
Copy

Once you have clicked 'Create new workflow' from your main Tray.io dashboard named it, select the Manual trigger from the trigger options available:

After you have been redirected to the Tray.io workflow dashboard, from the connectors panel on the left, add a Transport for London connector to your second step. Set the operation to 'List lines by mode'.

Feel free to re-name your steps as you go along to make things clearer for yourself and other users.

Choose the mode for which you would like the line statuses in the dropdown. You can also adjust the pagination of the results achieved to your preference.

This step will have retrieved the lines of the mode specified in the inputs.

2 - Loop Collection
Copy

Next, search for the 'Loop collection' connector within your connector panel, and drag it into your workflow as your next step. Set your operations to 'Loop list'.

The Loop Collection connector allows you to iterate through a list of results. In this example, we will use it to iterate through the data found within the previous Transport for London connector step.

In order to specify the list you want to loop through, start by using the 'List' mapping icon (found next to the list input field, within the properties panel) to generate the connector-snake.

While hovering over the 'List lines by mode' step (with the tail end of the connector-snake), select data from the list of output properties displayed. This will auto-populate a jsonpath within your 'List' input field, and update the type selector to jsonpath.

For more clarification on the pathways you have available, open the Debug panel to view your step's Input and Output.

JSONPATHS: For more information on what jsonpaths are and how to use jsonpaths with Tray, please see our pages on Basic data concepts and Mapping data between steps

CONNECTOR-SNAKE: The simplest and easiest way to generate your jsonpaths is to use our feature called the Connector-snake. Please see the main page for more details.

This step enables you to loop through the results of the previous step.

3 - List line statuses
Copy

The last step is to drag a Transport for London connector inside of the Loop Collection step itself. Set the operation to 'List line statuses for given lines'. As you can see, the 'Line ID' field is required.

Once again, use the connector snake an hover over the 'Loop Collection' step (with the tail end of the connector-snake), select value from the list of output properties displayed.

If you click on 'Debug' at the top of the page, you can see your workflow execution. As you can see, you can see the connector loop through the list of line statuses as provided by step 1.

If you click on each execution of 'List Line Statuses', you will be able to see the results of each loop.

BEST PRACTICES: Whenever you do decide to create your own workflow, be sure to check out some of our key articles such as: