bahn.com APIbahn.com ↗
Access Deutsche Bahn station data, train connections, ticket offers, and regional transit associations via the bahn.com API. 5 endpoints.
curl -X GET 'https://api.parse.bot/scraper/7dfccc04-525c-426d-8322-a10e7d62cd3b/get_station_autocomplete?query=Berlin' \ -H 'X-API-Key: $PARSE_API_KEY'
Search for stations by name. Returns a list of stations with their internal HAFAS IDs, coordinates, and available transport products.
| Param | Type | Description |
|---|---|---|
| queryrequired | string | Station name search query (e.g., 'Berlin', 'München') |
{
"type": "object",
"fields": {
"data": "array of station objects with id, extId, name, lat, lon, type, and products fields",
"status": "string indicating success"
},
"sample": {
"data": [
{
"id": "A=1@O=Berlin Hbf@X=13369549@Y=52525589@U=80@L=8011160@p=1777919315@i=U×008065969@",
"lat": 52.524925,
"lon": 13.369629,
"name": "Berlin Hbf",
"type": "ST",
"extId": "8011160",
"products": [
"ICE",
"EC_IC",
"IR",
"REGIONAL",
"SBAHN",
"BUS",
"UBAHN",
"TRAM"
]
}
],
"status": "success"
}
}About the bahn.com API
The bahn.com API provides 5 endpoints covering Deutsche Bahn station lookup, train connection search, and ticket offer retrieval. Use get_station_autocomplete to search stations by name and receive HAFAS IDs, coordinates, and transport product flags. Other endpoints expose traveler types, BahnCard discount codes, and regional transit association metadata for Germany's rail network.
Station and Reference Data
The get_station_autocomplete endpoint accepts a query string (e.g., 'Berlin' or 'München') and returns an array of matching station objects. Each object includes an id, an extId (the full HAFAS identifier used in connection searches), name, lat/lon coordinates, a type field, and a products field indicating which transport modes serve that station (e.g., long-distance rail, S-Bahn, bus).
The get_metadata endpoint requires no inputs and returns a structured object with five arrays: reisendenTypen (traveler types such as adult or child), reisendenTypenAll, ermaessigungsArten (BahnCard discount types), einstiegsTypen (boarding/entry types), and produktInfo (product definitions). This data is useful for populating dropdowns or validating parameters before submitting connection searches. get_transit_associations similarly requires no inputs and returns a list of German regional transit associations (Verkehrsverbünde), each with a code, kuerzel (abbreviation), description, shortDescription, logo URL, and a hatShop boolean indicating whether that association has an online shop.
Connection Search and Ticket Offers
search_connections accepts an origin_id and destination_id (both full HAFAS IDs from get_station_autocomplete) and an optional ISO 8601 departure_time. It returns a data object containing connection options with journey times, durations, and pricing where available. Note that this endpoint may be blocked in some environments due to WAF restrictions on the source site, so expect variable availability. Once you have a connection result, each journey includes a ctxRecon token. Pass that token to get_ticket_offers to retrieve detailed fare and ticket offer data for that specific connection.
Coverage Scope
All five endpoints are oriented around Deutsche Bahn's domestic and cross-border rail network. Station lookups cover DB-served stations with HAFAS identifiers. Transit association data covers German Verkehrsverbünde only. The connection search and ticket endpoints depend on HAFAS IDs obtained from the station autocomplete endpoint, so that lookup is the natural entry point for any journey-planning workflow.
- Build a station autocomplete widget using
name,lat,lon, andproductsfields fromget_station_autocomplete - Populate BahnCard discount dropdowns in a booking form using
ermaessigungsArtenfromget_metadata - Map all regional transit associations in Germany with their logos and shop links using
get_transit_associations - Query train connections between two cities by passing HAFAS
extIdvalues tosearch_connections - Retrieve fare breakdowns for a specific journey by passing a
ctxRecontoken toget_ticket_offers - Filter stations by transport product type (e.g., only ICE-served stations) using the
productsfield - Validate traveler type inputs in a booking UI using
reisendenTypenfromget_metadata
| 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 Deutsche Bahn offer an official developer API?+
What does `get_station_autocomplete` return beyond station names?+
id, an extId (the full HAFAS identifier required by search_connections), lat/lon coordinates, a type classification, and a products field that indicates which transport modes — such as long-distance rail, regional rail, S-Bahn, or bus — serve that station.Is real-time departure or delay information available?+
Are international routes outside Germany supported by `search_connections`?+
get_station_autocomplete results. Coverage reflects Deutsche Bahn's own booking inventory and is not a general European rail aggregator.What is the `ctxRecon` token and when is it needed?+
ctxRecon is a reconstruction token returned inside a connection result from search_connections. It uniquely identifies a specific journey and must be passed as the sole input to get_ticket_offers to retrieve the fare and ticket options for that journey. Without a valid ctxRecon from a prior search, get_ticket_offers cannot return meaningful data.