thetrainline.com APIwww.thetrainline.com ↗
Search UK train stations, find cheapest fares across date ranges, look up live journeys, and generate Trainline booking URLs via a simple REST API.
curl -X GET 'https://api.parse.bot/scraper/6ece94aa-46a7-4f0f-916f-e4855ba2a3fd/search_stations?limit=3&query=Manchester' \ -H 'X-API-Key: $PARSE_API_KEY'
Search for train stations by name. Returns matching stations with their Trainline URN codes (needed for other endpoints), coordinates, and metadata.
| Param | Type | Description |
|---|---|---|
| limit | integer | Maximum number of results to return |
| queryrequired | string | Station name or partial name to search for |
{
"type": "object",
"fields": {
"query": "string — the search term used",
"stations": "array of station objects with name, code, short_name, country_code, location_type, latitude, longitude, timezone, and optional parent_name",
"total_results": "integer — number of stations returned"
},
"sample": {
"data": {
"query": "Manchester",
"stations": [
{
"code": "urn:trainline:generic:loc:MAN2968gb",
"name": "Manchester Piccadilly",
"latitude": 53.4767,
"timezone": "Europe/London",
"longitude": -2.229,
"short_name": "MAN",
"parent_name": "Manchester",
"country_code": "GB",
"location_type": "station"
}
],
"total_results": 3
},
"status": "success"
}
}About the thetrainline.com API
The Trainline API covers 4 endpoints for working with UK rail data: search stations by name, look up journeys between two stations on a given date, find the cheapest fare per day across a 30-day window, and generate pre-filled booking URLs. The search_stations endpoint returns Trainline URN codes required as inputs to every other endpoint, making it the natural starting point for any integration.
Station Search and URN Codes
The search_stations endpoint accepts a full or partial station name and returns up to a configurable limit of matches. Each result includes the station's name, short_name, code, country_code, location_type, latitude, longitude, and timezone. The urn field from these results is the identifier you pass to origin and destination parameters in every other endpoint — without it, journey and fare lookups are not possible.
Journey Search
The search_journeys endpoint takes an origin URN, a destination URN, an optional date (ISO 8601 format), optional passengers count, currency (GBP, USD, or EUR), and a journey_type of single or return. Each journey object in the response includes depart_at, arrive_at, duration, changes, distance_km, co2_grams, a legs array, and a fares array. Note that this endpoint may be intermittently unavailable due to site protection on the source.
Cheapest Fares Calendar
The get_cheapest_fares endpoint scans a date range (defaulting to the next 30 days) and returns a daily_fares array with one price_amount and price_currency per day. A cheapest_fare object at the top level identifies the single lowest-priced day in the range — useful for flexible-date travel planning without iterating through individual journey searches.
Booking URL Generation
The get_booking_url endpoint produces a booking_url string that deep-links directly into Trainline's fare selection screen. Inputs include origin, destination, date, optional return_date, passengers, passenger_ages (comma-separated, e.g. 30,25), and journey_type. The URL is ready to hand off to a user who wants to complete the booking on Trainline's own site.
- Find the cheapest day to travel between two cities using
get_cheapest_faresdaily_fares data - Build a price-alert tool that monitors a route's
cheapest_fareover time and notifies users when it drops - Auto-complete station name inputs in a booking widget using
search_stationsresults - Display journey options with
changes,duration, andco2_gramsto help users compare routes - Generate affiliate or deep-link booking URLs via
get_booking_urlwith pre-filled passenger ages - Compare outbound fares across a date window to identify travel patterns for a specific route
- Embed a rail fare calendar in a travel itinerary app using date-indexed
daily_faresobjects
| Tier | Price | Credits/month | Rate limit |
|---|---|---|---|
| Free | $0/mo | 100 | 5 req/min |
| Hobby | $30/mo | 1,000 | 20 req/min |
| Developer | $100/mo | 5,000 | 250 req/min |
One credit = one API call regardless of which marketplace API you call. Exceeding the rate limit returns a 429 response. Authenticate with the X-API-Key header.
Does Trainline have an official public developer API?+
What does `search_journeys` return beyond just prices?+
depart_at, arrive_at, duration in minutes, changes count, distance_km, co2_grams, a legs array breaking down individual train segments, and a fares array with pricing options. The currency field in the request controls whether prices come back in GBP, USD, or EUR.Is `search_journeys` always available?+
get_cheapest_fares is a more stable alternative.