17 NOV 2026 / Written by Lukas / 8 MIN READ
Deutsche Bahn and public APIs
Because we all want to know about the delay before it happens.
On this page
I just wanted to know when the bloody bus leaves
The idea was simple: send Mike a Telegram message in the morning with the connections he needs for work, plus a heads-up if something is delayed or cancelled.
That means a bus, a tram, and sometimes an S-Bahn.
A fairly normal commute. Apparently also an invitation to learn far more about German public transport APIs than I had planned.
One correction before I accidentally write an entire post about the wrong company: the endpoint that made this work belongs to Leipzig’s LVB Stationboard service. I had been thinking about the problem as “find a Deutsche Bahn API,” but the local departure-board service turned out to cover the buses, trams and S-Bahn services I actually needed.
The DB side of the story is still worth explaining, because it accounts for a lot of the confusing examples floating around.
Older tutorials often use hafas-client with a Deutsche Bahn profile. The project’s own documentation now warns that the underlying DB HAFAS endpoint appears to have been permanently switched off and points users towards db-vendo-client. That is an upstream service disappearing, rather than every application using the library suddenly forgetting how to work. DB profile documentation
The hosted v6.db.transport.rest service is another concrete example: its documentation currently says that it is no longer operational. Meanwhile, db-vendo-client supports newer DB interfaces, but its maintainers warn about blocking and unreliable access. So “everything is dead” is a bit dramatic, but “this perfectly reasonable-looking tutorial may depend on a backend that has since disappeared” is very much a thing. db-rest service status, db-vendo-client
The maintainers deserve some sympathy here. Writing a wrapper around somebody else’s changing infrastructure sounds like a hobby that occasionally becomes unpaid incident response.
There is also an important distinction with VBB. The VBB HAFAS API does support buses and trams. Its documentation explicitly includes both. It is built around Berlin and Brandenburg, though, and seeing a railway station outside that region does not prove it has the local bus coverage needed for a Leipzig commute. The problem to check is geographical coverage and available realtime data, rather than assuming HAFAS itself only understands trains. VBB overview, VBB API documentation
DB’s IRIS/Timetables API is a different product again: it deals with railway station boards and train information. Useful, but that does not solve the Bus part of my problem. DB Timetables
Anyway. The bus.
LVB Stationboard is a service for building your own departure display. Pick a stop, configure the display, and open or embed it. LVB explicitly describes support for buses, trams, regional trains and S-Bahn services in the Leipzig region.
That is a much better starting point for this particular project.
The useful requests are visible in the website’s frontend. Open the browser’s developer tools, select the Network tab, filter for Fetch/XHR, and search for a stop. The autocomplete makes a request like this:
curl --fail --silent --show-error --get \
'https://stationboard.l.de/api/stops' \
--data-urlencode 'searchTerm=Lipsius' |
jq '.[] | {name, stop_id: .tags.stop_id}'
When checked for this post, that returned:
{
"name": "Leipzig, Lipsiusstr.",
"stop_id": "0010750"
}
The full result contains more information, including coordinates and parent-station metadata. For the departure request, the useful value is tags.stop_id.
Keep that value as a string. Those leading zeroes are part of the identifier you received.
Searching for Miltitz also demonstrates why grabbing the first vaguely matching result is a bad idea. The response contains separate entries for Bahnhof Miltitz, Miltitz’s tram/bus stop, Miltitz S-Bahn, and Miltitzer Allee S-Bahn.
Those names are annoyingly similar when you are trying to make a computer understand where a person needs to go.
These are the IDs used in our workflow:
| Stop or station board | ID |
|---|---|
| Lipsiusstraße | 0010750 |
| Riebeck-/Oststraße | 0011330 |
| Ostplatz | 0011972 |
| Hauptbahnhof tram stops | 0013000 |
| Leipzig Hbf railway board used for S6 | 8010205 |
| Leipzig-Miltitz S-Bahn | 8012355 |
These belong to this service. I would not blindly paste them into another provider’s API and assume they mean the same thing.
Once you have a stop ID, fetching departures is pleasantly boring:
curl --fail --silent --show-error --get \
'https://stationboard.l.de/api/stops/0010750' \
--data-urlencode "date=$(TZ=Europe/Berlin date +%Y%m%d)" \
--data-urlencode "time=$(TZ=Europe/Berlin date +%H:%M)" \
--data-urlencode 'numRows=30' \
--data-urlencode 'transportTypes=bahn_bus_sbahn_tram_rufbus' |
jq '.'
The parameters used here are:
| Parameter | What I send |
|---|---|
date |
The local date as YYYYMMDD |
time |
The local time as HH:mm |
numRows |
The requested row count |
transportTypes |
The underscore-separated transport filters used by the frontend |
Use Leipzig time, rather than whatever timezone your server happens to use.
The response is a JSON array. Requests checked for this post worked without an API key, and the same endpoint pattern returned Bus 60 at Lipsiusstraße, Tram 15 at Ostplatz, and S6 departures at Hauptbahnhof.
I am describing the website’s observed interface here, rather than claiming there is a permanently supported, versioned developer API behind these URLs.
Here is a shortened real response observed on 17 November 2026, from the Hauptbahnhof board:
{
"departure_date": "20261117",
"departure_time": "13:06:00",
"trip_id": "800486_000321_010699_2",
"service_date": "20261117",
"line": "S6",
"trip_headsign": "Naumburg (Saale) Hbf",
"agencyName": "DB Regio AG Südost",
"trip_cancelled": false,
"stop_cancelled": false,
"track_scheduled": "7",
"track": "7",
"departure_delay": 480,
"transport_type": "S-Bahn"
}
That 480 is important.
It represents seconds, so this was an eight-minute departure delay. The scheduled time was 13:06; applying the reported delay gives 13:14.
It was not eight hours late. My first requirement for this bot is that it should not accidentally make German public transport sound worse through arithmetic.
The workflow keeps the scheduled time and expected time separate:
expected departure = scheduled departure + departure delay
expected arrival = scheduled arrival + arrival delay
It also keeps “no reported delay” separate from “no realtime delay available.”
That distinction is easy to lose with something like:
const delay = row.departure_delay || 0;
If the value is missing, that quietly turns uncertainty into an on-time prediction.
A small normalization helper makes the intention clearer:
function optionalNumber(value) {
if (value === null || value === undefined || value === "") {
return null;
}
const number = Number(value);
return Number.isFinite(number) ? number : null;
}
const delaySeconds = optionalNumber(row.departure_delay);
const delayMinutes =
delaySeconds === null ? null : Math.round(delaySeconds / 60);
const delayLabel =
delayMinutes === null
? "Live delay unavailable; showing timetable"
: delayMinutes === 0
? "No reported delay"
: `Delay: ${delayMinutes} min`;
Cancellation flags matter separately. A cancelled departure with a zero delay is still cancelled. The workflow checks both trip_cancelled and stop_cancelled, and prefers track over track_scheduled when a current platform is available.
Then comes the part that actually took some thought: connecting the boards.
A list of the next buses and the next trains is useful, but it can also confidently suggest a connection that requires teleportation.
Our workflow fetches six boards and matches the relevant services across them. The normalized matching rule uses trip ID plus service date. A line number alone is useless for identifying a particular vehicle run: there are quite a few Bus 60s over the course of a day.
The route logic roughly does this:
- Find an appropriate Bus 60 departure at Lipsiusstraße, in the correct direction.
- Find that same trip at Riebeck-/Oststraße or Ostplatz.
- Allow time to change to Tram 4 or Tram 15.
- Find that tram’s visit to Hauptbahnhof.
- Allow time to walk from the tram stop to the railway platform.
- Find a suitable S6 and match its visit to Leipzig-Miltitz.
- Check that the remaining walk still fits the arrival target.
The buffers in our setup are five minutes to reach the first bus, three minutes for the bus-to-tram change, ten minutes at Hauptbahnhof, and another five minutes at the destination.
Those are our assumptions. They are not a promise from the API about how quickly anyone can get across a station.
Direction filtering matters just as much. “Next S6” is not enough. It needs to be the S6 travelling towards the intended destination. Likewise, Miltitzer Allee cannot be substituted for Leipzig-Miltitz because both names contain “Miltitz.”
This is still a departure-board matcher for a handful of known routes. It does not search every possible journey across the network.
That limitation shows up with the direct Tram 15 alternative: the current implementation can identify a suitable departure towards Miltitz, but it does not fetch and match that tram’s terminal arrival. The message says the arrival time is unavailable rather than inventing one.
In n8n, the main flow is:
Scheduled trigger
→ weekday and holiday check
→ fetch the relevant departure boards
→ normalize times, delays and cancellations
→ match the known connections
→ compare disruptions with the last notification
→ send Telegram message when needed
There is an early morning reminder, a fresh commute summary, and checks every ten minutes through the commute window. Later messages are sent for new relevant disruptions rather than repeating the entire timetable every time.
The requests have timeouts and bounded retries. If a board fails, the message reports missing data. It does not translate an API error into “everything looks fine.”
The workflow also records notification state only after Telegram confirms delivery, so a failed send does not permanently suppress the message that was supposed to go out.
I am keeping the requests limited to the stops and times needed. The stationboard is a useful public service, and there is no reason for my little household bot to hammer it all day.
There are other approaches for bigger projects. The DB client maintainers point towards GTFS/GTFS-RT data and routing tools such as MOTIS; Transitous provides a community-operated routing service with its own usage policy. Those are worth investigating when the requirement grows beyond a few known commute connections. Alternative approaches, Transitous API and usage policy
For now, I have a Telegram message that can tell us about the bus, the tram and the train without pretending a missing delay value means good news.
It also includes a fun fact.
If the commute is going to be annoying, we might as well learn something about an octopus.
