Discover/thetrainline.com API
live

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.

Endpoints
4
Updated
1mo ago
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.
Use it in your codegrab a free API key at signup
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'
All endpoints · 4 totalclick to expand

Search for train stations by name. Returns matching stations with their Trainline URN codes (needed for other endpoints), coordinates, and metadata.

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": "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.

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,000250 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 www.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.