Discover/Thetrainline API
live

Thetrainline APIthetrainline.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.

Endpoint health
verified 2d ago
search_stations
get_cheapest_fares
get_booking_url
search_journeys
4/4 passing latest checkself-healing
Endpoints
4
Updated
22d ago

What is the Thetrainline 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.

Try it
Maximum number of results to return
Station name or partial name to search for
api.parse.bot/scraper/6ece94aa-46a7-4f0f-916f-e4855ba2a3fd/<endpoint>
Ready to send
Fill in the parameters and hit sign in to send to see live response data here.
Call it over HTTPgrab a free API key at signup
curl -X GET 'https://api.parse.bot/scraper/6ece94aa-46a7-4f0f-916f-e4855ba2a3fd/search_stations?limit=10&query=Manchester' \
  -H 'X-API-Key: $PARSE_API_KEY'
Python SDK · recommended

Typed, relational, agent-ready

A generated client with real types, enums, and the links between objects — the structure a flat JSON response can't carry. Autocompletes in your editor and reads cleanly to coding agents.

  • Fully typed · autocompletes
  • Objects link to objects
  • Typed errors & pagination

Typed Python client. Set up the SDK in your uv project, then pull this API’s typed client:

uv add parse-sdk
uv run parse init
uv run parse add --marketplace thetrainline-com-api

uv run parse add --marketplace pulls a pinned snapshot of this canonical API — it won’t change underneath you. To customize it, subscribe and swap to your own copy.

from parse_apis.trainline_uk_train_search_api import Trainline, JourneyType, Currency

trainline = Trainline()

# Search for stations by name
for station in trainline.stations.search(query="Manchester"):
    print(station.name, station.code, station.country_code)

# Use a route to find cheapest fares across dates
route = trainline.route(origin="urn:trainline:generic:loc:MAN2968gb")

for fare in route.get_cheapest_fares(
    destination="urn:trainline:generic:loc:EUS1444gb",
    currency=Currency.GBP,
):
    print(fare.date, fare.price_amount, fare.price_currency)

# Search journeys on a specific date
for journey in route.search_journeys(
    destination="urn:trainline:generic:loc:EUS1444gb",
    date="2026-07-01T09:00",
    journey_type=JourneyType.SINGLE,
    currency=Currency.GBP,
):
    print(journey.depart_at, journey.arrive_at, journey.duration, journey.changes, journey.co2_grams)

# Generate a booking URL
booking = route.get_booking_url(
    destination="urn:trainline:generic:loc:EUS1444gb",
    date="2026-07-01T09:00",
    journey_type=JourneyType.SINGLE,
)
print(booking.booking_url, booking.passengers)
All endpoints · 4 totalmissing one? ·

Search for train stations by name. Returns matching stations with their Trainline URN codes (needed as origin/destination inputs for other endpoints), coordinates, country, timezone, and optional parent station group. Supports partial name matching across UK and European networks.

Input
ParamTypeDescription
limitintegerMaximum number of results to return
queryrequiredstringStation name or partial name to search for
Response
{
  "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": "London",
      "stations": [
        {
          "code": "urn:trainline:generic:loc:EUS1444gb",
          "name": "London Euston",
          "latitude": 51.5284,
          "timezone": "Europe/London",
          "longitude": -0.1346,
          "short_name": "EUS",
          "parent_name": "London",
          "country_code": "GB",
          "location_type": "station"
        }
      ],
      "total_results": 5
    },
    "status": "success"
  }
}

About the Thetrainline API

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.

Reliability & maintenanceVerified

The Thetrainline API is a managed, monitored endpoint for thetrainline.com — not a raw scraper you maintain. Every endpoint is automatically health-checked on a schedule, and when thetrainline.com changes and a check fails, the API is automatically queued for repair and re-verified. It is built to keep working as the site underneath it changes.

This isn't an official thetrainline.com API — it's an independent, maintained REST wrapper over public data. Where the source has no official API (or only a limited one), Parse gives you a stable contract over a source that never promised one, and keeps it current. Need a new endpoint or field? You can revise it yourself in plain English and the agent rebuilds it against the live site in minutes — contributing the change back to the shared API is free.

Last verified
2d ago
Latest check
4/4 endpoints passing
Maintenance
Monitored & self-healing
Will this API break when the source site changes?+
It's built not to. Every endpoint is health-checked on a schedule with automated test probes. When the source site changes and a check fails, the API is automatically queued for repair and re-verified — that's the self-healing layer. Each API page shows when its endpoints were last verified. And because marketplace APIs are shared, any fix reaches everyone using it.
Is this an official API from the source site?+
No — Parse APIs are independent, managed REST wrappers over publicly available data. That is the point: where a site has no official API (or only a limited one), Parse gives you a maintained, monitored endpoint for that data and keeps it working as the site changes — so you get a stable contract over a source that never promised one.
Can I fix or extend this API myself if I need a new endpoint or field?+
Yes — and you don't have to wait on us. This API was generated by the Parse agent, which stays attached. Describe the change in plain English ("add an endpoint that returns reviews", "fix the price field") in the revise box on the API page or via the revise_api MCP tool, and the agent rebuilds it against the live site in minutes. Contributing the change back to the public API is free.
What happens if I call an endpoint that has an issue?+
Errors are machine-readable: a bad call returns a clean status with the list of available endpoints and a repair hint, so an agent (or you) can recover or trigger a fix instead of failing silently. Confirmed failures feed the automatic repair queue.
Common use cases
  • Find the cheapest day to travel between two cities using get_cheapest_fares daily_fares data
  • Build a price-alert tool that monitors a route's cheapest_fare over time and notifies users when it drops
  • Auto-complete station name inputs in a booking widget using search_stations results
  • Display journey options with changes, duration, and co2_grams to help users compare routes
  • Generate affiliate or deep-link booking URLs via get_booking_url with 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_fares objects
Pricing & limitsSee full pricing →
TierPriceCredits/monthRate limit
Free$0/mo1005 req/min
Hobby$30/mo1,00020 req/min
Developer$100/mo5,000100 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.

Frequently asked questions
Does Trainline have an official public developer API?+
Trainline does not offer a public developer API. There is no documented endpoint or API key program available to third-party developers on their site.
What does `search_journeys` return beyond just prices?+
Each journey object includes 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?+
Not always. The endpoint notes it may be intermittently blocked by site protection on thetrainline.com. For fare availability across dates without per-journey detail, get_cheapest_fares is a more stable alternative.
Does the API cover rail routes outside the UK, such as European trains?+
The current endpoints are scoped to UK rail data and Trainline's UK station network. International or European cross-border routes are not currently covered. You can fork this API on Parse and revise it to add an endpoint targeting European route data.
Can I retrieve seat availability or specific carriage details for a journey?+
Not currently. The API returns fare amounts, journey duration, change counts, and leg-level data, but does not expose seat maps or carriage-level availability. You can fork the API on Parse and revise it to add an endpoint that surfaces that detail.
Page content last updated . Spec covers 4 endpoints from thetrainline.com.
Related APIs in TravelSee all →
trainline.eu API
Search for train stations and routes across the UK and Europe, then find and compare available journeys with schedules and pricing. Book your ideal train trip by accessing real-time travel options directly from Trainline.com.
nationalrail.co.uk API
Check live train departure and arrival times at UK stations, search for specific stations, and get real-time service disruption alerts. Stay informed about rail service delays and changes to plan your journeys efficiently.
amtrak.com API
Search for Amtrak trains across stations, compare fares, and discover discounts to plan your rail journey with current pricing and availability. Get detailed train information, autocomplete station names, and find the cheapest routes for your travel dates.
trenitalia.com API
Search for trains across Italy, check real-time train status and delays, view station departure and arrival boards, and find available tickets all in one place. Get live traffic information and detailed train itineraries to plan your journey with complete visibility into schedules and service disruptions.
railyatri.in API
Search trains between stations and get real-time information including live train status, timetables, seat availability, and PNR confirmation details. Find the perfect journey by autocompleting station and train names while checking current availability and train schedules.
enquiry.indianrail.gov.in API
Search for trains between Indian stations, check schedules, and look up station details to plan your rail journeys. Get real-time train information with support for captcha-protected searches to ensure reliable access to Indian Railways data.
bahn.com API
Search German train schedules and stations, find connections between destinations, and compare ticket prices across Deutsche Bahn routes. Get real-time station information and transit association details to plan your train journey efficiently.
omio.com API
Search and compare train, bus, and flight trips across multiple providers in real-time, with detailed pricing breakdowns and the ability to view fares across different dates. Find the best deals by exploring popular destinations, autocompleting location searches, and analyzing price variations to plan your ideal journey.