Swiss Public Transport

Transportation API · Switzerland · Train, bus, boat schedules

How to Use This API

1. Search Stations

https://transport.opendata.ch/v1/locations?query=Zürich

2. Station Board (Departures)

https://transport.opendata.ch/v1/stationboard?id=8503000&limit=10

8503000 is Zürich HB's station ID.

3. Journey Between Two Stations

https://transport.opendata.ch/v1/connections?from=Zürich&to=Bern

4. Journey with Time and Date

https://transport.opendata.ch/v1/connections?from=Lausanne&to=Geneva&time=08:30&date=2026-06-20

5. JavaScript — Next Departures

async function nextDepartures(station, limit = 5) {
  const resp = await fetch(
    `https://transport.opendata.ch/v1/stationboard?id=${station}&limit=${limit}`
  );
  const data = await resp.json();
  
  data.stationboard.forEach(dep => {
    const cat = dep.category;
    const num = dep.number;
    const dest = dep.to;
    const time = dep.stop.departure.slice(11, 16);
    console.log(`${cat}${num} → ${dest} at ${time}`);
  });
}

nextDepartures('8503000'); // Zurich HB

6. Python — Journey Planner

import requests

def plan_journey(from_station, to_station):
    resp = requests.get(
        'https://transport.opendata.ch/v1/connections',
        params={'from': from_station, 'to': to_station, 'limit': 3}
    )
    data = resp.json()
    
    for i, conn in enumerate(data['connections'][:3], 1):
        dep = conn['from']['departure'][11:16]
        arr = conn['to']['arrival'][11:16]
        dur = conn['duration']
        print(f'{i}. Depart {dep} → Arrive {arr} ({dur})')
        
        for section in conn['sections']:
            j = section.get('journey', {})
            if j:
                print(f'   {j["category"]}{j["number"]} from '
                      f'{section["departure"]["station"]["name"]}')

plan_journey('Bern', 'Interlaken')

TL;DR

The Swiss Public Transport API (transport.opendata.ch) provides complete access to Switzerland's legendary transit system — SBB/CFF/FFS trains, trams, buses, boats, cable cars, and postal buses. Search stations, get real-time departure boards, plan multi-leg journeys with connections, and access detailed stop information including platform numbers, delays, and coordinates. Covers the entire Swiss transport network with the precision you'd expect from Swiss railways. Completely free, open data, no API key required.

Quick start: https://transport.opendata.ch/v1/connections?from=Zürich&to=Bern

No API key needed — just make a request!

Zurich to Bern connections: https://transport.opendata.ch/v1/connections?from=Zürich&to=Bern

Frequently Asked Questions

What transport modes are covered?
All Swiss public transport: SBB/CFF/FFS railways, S-Bahn (suburban trains), trams, buses, postal buses (PostAuto), boats/ships, and cable cars/funiculars.
Do I need an API key?
No. This is an open data API provided by the Swiss Federal Railways (SBB) through opendata.ch. No registration needed.
How do I find station IDs?
Use the locations endpoint to search by name. Each station has a unique numeric ID (e.g., 8503000 for Zürich HB) that can be used for precise queries.
Is real-time delay information available?
Yes, departure and arrival objects include delay fields (in minutes), platform (track number), and prognosis status.
How many results can I get?
Use the limit parameter (default 4, max 20 for connections, higher for stationboard). Connections results include detailed section-by-section breakdowns.
Can I filter by transport type?
Not directly, but you can filter results client-side. Each journey section includes a category (ICE, IR, S, BUS, TRAM, SHIP, etc.).

API Details

API URL
https://transport.opendata.ch/v1/
Documentation
transport.opendata.ch
Category
Transportation
Authentication
Not Required
Geographic Coverage
Switzerland (including cross-border connections to neighboring countries)

What You Can Build