Check Deutsche Bahn train connections, real-time delays, ticket prices, and Bahncard discounts. Use when users need to check if their train or bus is on time, find connections between stations, get departure boards with delay information, look up station IDs, check ticket prices, or compare Bahncard savings. Supports db-vendo-client with real-time delay data, pricing, and loyalty card integration from German public transport.
Check Deutsche Bahn train connections and real-time delay information using the db-vendo-client API.
To check if a train is on time:
import { createClient } from 'db-vendo-client';
import { profile as dbnavProfile } from 'db-vendo-client/p/dbnav/index.js';
const client = createClient(dbnavProfile, 'user-agent');
const { departures } = await client.departures('8098160', { // Berlin Hbf
when: new Date(),
duration: 60
});
departures.forEach(dep => {
const delay = dep.delay ? Math.round(dep.delay / 60) : 0;
console.log(`${dep.line.name}: ${delay} min delay`);
});
To find connections:
Use the bundled scripts/check-route.mjs script or the journeys() endpoint. See API Reference for details.
Use the scripts/check-delays.mjs script to check upcoming departures:
node scripts/check-delays.mjs
Edit the script to change the station ID or duration.
Use scripts/check-route.mjs to check connections between two stations:
node scripts/check-route.mjs
Use the locations() method:
const stations = await client.locations('München');
console.log(stations[0].id); // e.g., 8000261 for München Hbf
See Station IDs for common stations.
Use scripts/check-price.mjs to check ticket prices for routes:
node scripts/check-price.mjs
Or use the journeys() endpoint:
const { journeys } = await client.journeys(fromId, toId, {
departure: new Date(),
results: 3
});
journeys.forEach(j => {
if (j.price) {
console.log(`Price: ${j.price.amount} ${j.price.currency}`);
}
});
With Bahncard discounts:
The skill supports Bahncard pricing. Specify loyalty card for discounted prices:
import { data as cards } from 'db-vendo-client/format/loyalty-cards.js';
const { journeys } = await client.journeys(fromId, toId, {
departure: new Date(),
results: 3,
loyaltyCard: {
type: cards.BAHNCARD,
discount: 25, // or 50
class: 2 // 1st or 2nd class
}
});
Note: Pricing is returned in EUR and may vary based on time, train type, Bahncard status, and availability.
const { departures } = await client.departures(stationId, {
when: new Date(),
duration: 60,
remarks: true
});
departures.forEach(dep => {
console.log(`${dep.line.name} to ${dep.direction}`);
console.log(`Planned: ${dep.plannedWhen}`);
console.log(`Actual: ${dep.when}`);
console.log(`Delay: ${dep.delay ? Math.round(dep.delay/60) + ' min' : 'On time'}`);
if (dep.cancelled) {
console.log('⚠️ CANCELLED');
}
if (dep.remarks?.length > 0) {
console.log(`Remarks: ${dep.remarks.length}`);
}
});
Use departures() for delays - The journeys() endpoint does NOT include real-time delays. Only departures() provides delay data.
Delay is in seconds - Convert to minutes: Math.round(dep.delay / 60)
null delay means on time - Not missing data
Choose the right profile - See API Reference for profile comparison (dbnav recommended for most use cases)
Respect rate limits - Use caching to avoid blocking
Each departure object contains:
plannedWhen - Scheduled departure timewhen - Actual/prognosed departure timedelay - Delay in seconds (null if on time)cancelled - True if service is cancelledplatform - Current platform (may differ from plannedPlatform)remarks - Array of disruption informationNo delay data returned?
Rate limit errors?
cached-hafas-client wrapper)Station not found?
locations() to search for the station name and get the correct ID