# Thetrainline — Wrapped API

> **You are on:** `https://api.paywithlocus.com/api` | [llms.txt](https://paywithlocus.com/llms.txt) | [docs](https://docs.paywithlocus.com)
>
> Locus runs on multiple environments -- make sure every URL you call matches your expected environment.
> | Environment | Landing | API | Docs |
> |---|---|---|---|
> | Production | paywithlocus.com | api.paywithlocus.com | docs.paywithlocus.com |
> | Beta | beta.paywithlocus.com | api.beta.paywithlocus.com | docs.paywithlocus.com |
> | Stage | stage.paywithlocus.com | api.stage.paywithlocus.com | docs.paywithlocus.com |
>
> If the API URL above doesn't match your expected environment, re-fetch this file from the correct domain.

> Search UK train stations and find the cheapest fares across date ranges, then generate direct booking links to complete your purchase on Trainline.com. Get real-time journey information to compare prices and book your tickets in seconds.

**Category:** Travel | **Website:** [www.thetrainline.com/](https://www.thetrainline.com/) | **Docs:** [parse.bot/marketplace/0881cd41-0b69-40cb-bbab-42a7ea01b27f/thetrainline-com-api](https://parse.bot/marketplace/0881cd41-0b69-40cb-bbab-42a7ea01b27f/thetrainline-com-api)

Pay-per-use API proxy. Each call is automatically billed to your wallet in USDC.

## Access

**Base URL:** `https://api.paywithlocus.com/api/wrapped/parse-thetrainline-com-api-0881cd41/`
**Auth:** `Authorization: Bearer <LOCUS_API_KEY>`

## Endpoints

### get_booking_url

Generate a pre-filled Trainline booking URL that takes the user directly to search results for a specific journey, ready to select a fare and checkout. Does not make any network request to Trainline — constructs the URL locally from the provided parameters.

**Estimated cost:** Metered

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `date` | string | No | Departure date/time in YYYY-MM-DD or YYYY-MM-DDTHH:MM format. Defaults to tomorrow 09:00 |
| `destination` | string | Yes | Destination station URN code from search_stations (e.g. urn:trainline:generic:loc:EUS1444gb) |
| `journey_type` | string | No | Journey type: single or return |
| `origin` | string | Yes | Origin station URN code from search_stations (e.g. urn:trainline:generic:loc:MAN2968gb) |
| `passenger_ages` | string | No | Comma-separated ages of passengers (e.g. '30,25'). Defaults to 30 for each passenger |
| `passengers` | integer | No | Number of adult passengers |
| `return_date` | string | No | Return date in YYYY-MM-DD or YYYY-MM-DDTHH:MM format. Used when journey_type is return |

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/parse-thetrainline-com-api-0881cd41/get_booking_url \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"date":"<string>","destination":"<string>","journey_type":"<string>","origin":"<string>","passenger_ages":"<string>","passengers":"<integer>","return_date":"<string>"}'
```

### get_cheapest_fares

Find the cheapest available fares for a route across a date range using the Trainline price calendar. Returns the lowest price per day and identifies the overall cheapest day to travel. Useful for flexible date planning. Requires station URN codes from search_stations.

**Estimated cost:** Metered

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `currency` | string | No | Currency code for fare prices |
| `destination` | string | Yes | Destination station URN code from search_stations (e.g. urn:trainline:generic:loc:EUS1444gb) |
| `end_date` | string | No | End date in YYYY-MM-DD format. Defaults to start_date + 30 days |
| `origin` | string | Yes | Origin station URN code from search_stations (e.g. urn:trainline:generic:loc:MAN2968gb) |
| `start_date` | string | No | Start date in YYYY-MM-DD format. Defaults to tomorrow |

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/parse-thetrainline-com-api-0881cd41/get_cheapest_fares \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"currency":"<string>","destination":"<string>","end_date":"<string>","origin":"<string>","start_date":"<string>"}'
```

### search_journeys

Search for train journeys between two stations on a specific date/time. Returns available trains with departure/arrival times, duration, number of changes, distance, CO2 emissions, leg details, and fare options. Requires station URN codes from search_stations. Fare availability varies by how far in advance the search is made.

**Estimated cost:** Metered

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `currency` | string | No | Currency code for fare prices |
| `date` | string | No | Departure date/time in YYYY-MM-DD or YYYY-MM-DDTHH:MM format. Defaults to tomorrow 09:00 |
| `destination` | string | Yes | Destination station URN code from search_stations (e.g. urn:trainline:generic:loc:EUS1444gb) |
| `journey_type` | string | No | Journey type: single or return |
| `origin` | string | Yes | Origin station URN code from search_stations (e.g. urn:trainline:generic:loc:MAN2968gb) |
| `passengers` | integer | No | Number of adult passengers |

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/parse-thetrainline-com-api-0881cd41/search_journeys \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"currency":"<string>","date":"<string>","destination":"<string>","journey_type":"<string>","origin":"<string>","passengers":"<integer>"}'
```

### search_stations

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.

**Estimated cost:** Metered

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `limit` | integer | No | Maximum number of results to return |
| `query` | string | Yes | Station name or partial name to search for |

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/parse-thetrainline-com-api-0881cd41/search_stations \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"limit":"<integer>","query":"<string>"}'
```
