Using Microsoft Flow and TFL API to retrieve Travel Time

Here is an example of using Microsoft flow to calculate estimated travel time from one location to another. This would be very useful for Field agents who travel primarily on trains and public transport.

Below is the link to test your construction of the TFL API request.!/Journey/Journey_JourneyResults

In this example I am calculating the travel time on creation of a Booking from the users home location in Loughton to their first booking of the day in Holborn. This example does not cater for calculating journey time between two bookings as this is just one example.

Below I have an image of the first part of my Flow. On the left side of the parallel branch I am getting the date and time values from the field ‘starttime’. Below are the formatting of these variables:

Get Date – formatDateTime(triggerBody()?[‘starttime’], ‘yyyyMMdd’)

Get Time – formatDateTime(triggerBody()?[‘starttime’], ‘HHmm’)

On the right side of the branch I am retrieving the Resource’s user profile to later retrieve their postcode.

Next I am constructing my GET request. I am only adding 4 parameters but you could add more by going to the TFL API link at the beginning of this post and testing more parameters.

This is what the GET Request looks like with all the values populated:

URI – 4PD/to/WC2B 6AA?nationalSearch=true&date=20190211&time=1305

This is what the GET Request retrieves when its called (I have trimmed the body as its quite large):

Body – { “$type”: “Tfl.Api.Presentation.Entities.JourneyPlanner.ItineraryResult, Tfl.Api.Presentation.Entities”, “journeys”: [ { “$type”: “Tfl.Api.Presentation.Entities.JourneyPlanner.Journey, Tfl.Api.Presentation.Entities”, “startDateTime”: “2019-02-11T13:03:00”, “duration”: 44, “arrivalDateTime”: “2019-02-11T13:47:00”,

Next I am placing the body of the request into an object which then the variables can be accessed and used. In this case I am interested in the ‘duration’ value from the request as this is the total journey time and adding into the ‘Estimated Travel Duration’ field on the Bookable Resource Booking using this expression:

Estimated Travel Duration – variables(‘TFL’)[‘journeys’][0][‘duration’]

Once the flow has executed you will see that the travel duration has updated on the Schedule Board:

Leave a Reply

Your email address will not be published. Required fields are marked *