# Swiss Transit API
> Switzerland's public-transport timetable as an API, powered by the official Swiss open transport service (transport.opendata.ch, built on the search.ch timetable). One of the densest and most punctual transit networks in the world — trains (SBB/CFF/FFS), trams, city and postbuses, boats, funiculars and cable cars — in a single clean API. Find stops, stations and addresses by name with their identifier and coordinates; plan a complete door-to-door journey between any two places with optional via stop, date and time and the option to search by arrival time, getting each connection's departure and arrival times and platforms, total duration in minutes, the number of transfers, the transport products used (for example IC 8 or S 8) and the full leg-by-leg breakdown including any walking sections; and read a station's live departure or arrival board with the line, destination, time, platform and any real-time delay. Ideal for journey-planner and mobility apps, travel tools, logistics and tourism in Switzerland. Place names accept stop names or station ids from the locations endpoint, and times include live delays where available. Data from transport.opendata.ch (Swiss open transport data); covers Switzerland and immediate cross-border connections.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/swisstransit-api/..."
```

## Pricing
- **Free** (Free) — 595 calls/Mo, 2 req/s
- **Starter** ($7/Mo) — 21,600 calls/Mo, 6 req/s
- **Pro** ($22/Mo) — 91,200 calls/Mo, 15 req/s
- **Mega** ($60/Mo) — 388,000 calls/Mo, 40 req/s

## Endpoints

### Transit

#### `GET /v1/connections` — Plan a journey

**Parameters:**
- `from` (query, required, string) — Origin, e.g. Bern Example: `Bern`
- `to` (query, required, string) — Destination, e.g. Zurich Example: `Zurich`
- `via` (query, optional, string) — Optional via stop
- `date` (query, optional, string) — YYYY-MM-DD
- `time` (query, optional, string) — HH:MM
- `limit` (query, optional, string) — Max connections (1-16)

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/swisstransit-api/v1/connections?from=Bern&to=Zurich"
```

**Response:**
```json
{
    "data": {
        "to": "Zurich",
        "from": "Bern",
        "count": 4,
        "connections": [
            {
                "legs": [
                    {
                        "to": "St. Gallen",
                        "from": "Bern",
                        "line": "IC 1",
                        "type": "transit",
                        "arrival": "2026-06-01T19:28:00+0200",
                        "departure": "2026-06-01T18:31:00+0200",
                        "departure_platform": "8"
                    }
                ],
                "arrival": "2026-06-01T19:28:00+0200",
                "products": [
                    "IC 1"
                ],
                "departure": "2026-06-01T18:31:00+0200",
                "transfers": 0,
                "arrival_platform": "33",
                "duration_minutes": 61,
                "departure_platform": "8"
            },
            {
                "legs": [
                    {
                        "to": "Zürich HB",
                        "from": "Bern",
                        "line": "IR 16",
                        "type": "transit",
                        "arrival": "2026-06-01T19:54:00+0200",
                        "departure": "2026-06-01T18:36:00+0200",
                        "departure_platform": "12"
                    }
                ],
                "arrival": "2026-06-01T19:54:00+0200",
                "products": [
                    "IR 16"
                ],
  
…(truncated, see openapi.json for full schema)
```

#### `GET /v1/locations` — Find stops & stations

**Parameters:**
- `query` (query, required, string) — Place name, e.g. Bern Example: `Bern`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/swisstransit-api/v1/locations?query=Bern"
```

**Response:**
```json
{
    "data": {
        "count": 10,
        "query": "Bern",
        "locations": [
            {
                "id": "8507000",
                "name": "Bern",
                "type": "train",
                "latitude": 46.948823,
                "longitude": 7.439123
            },
            {
                "id": "8576646",
                "name": "Bern, Bahnhof",
                "type": "tram",
                "latitude": 46.948095,
                "longitude": 7.440213
            },
            {
                "id": "8579896",
                "name": "Bern, Hirschengraben",
                "type": "tram",
                "latitude": 46.946664,
                "longitude": 7.437626
            },
            {
                "id": "8507110",
                "name": "Bern, Zytglogge",
                "type": "tram",
                "latitude": 46.947834,
                "longitude": 7.447504
            },
            {
                "id": "8516161",
                "name": "Bern Wankdorf",
                "type": "train",
                "latitude": 46.967818,
                "longitude": 7.465483
            },
            {
                "id": "8504108",
                "name": "Bern Europaplatz",
                "type": "train",
                "latitude": 46.944204,
                "longitude": 7.406116
            },
            {
                "id": "8588989",
                "name": "Bern, Bärenplatz",
                "type": "tram",
             
…(truncated, see openapi.json for full schema)
```

#### `GET /v1/stationboard` — Live departure/arrival board

**Parameters:**
- `station` (query, required, string) — Station, e.g. Bern Example: `Bern`
- `type` (query, optional, string) — departure|arrival
- `limit` (query, optional, string) — Max (1-40)

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/swisstransit-api/v1/stationboard?station=Bern"
```

**Response:**
```json
{
    "data": {
        "type": "departure",
        "board": [
            {
                "to": "Jegenstorf",
                "line": "S 8",
                "arrival": null,
                "operator": "RBS",
                "platform": "24",
                "departure": "2026-06-01T18:24:00+0200",
                "delay_minutes": 0
            },
            {
                "to": "Worb Dorf",
                "line": "S 7",
                "arrival": null,
                "operator": "RBS",
                "platform": "23",
                "departure": "2026-06-01T18:30:00+0200",
                "delay_minutes": 0
            },
            {
                "to": "Biel/Bienne",
                "line": "S 3",
                "arrival": null,
                "operator": "BLS-bls",
                "platform": "10",
                "departure": "2026-06-01T18:30:00+0200",
                "delay_minutes": 0
            },
            {
                "to": "St. Gallen",
                "line": "IC 1",
                "arrival": null,
                "operator": "SBB",
                "platform": "8",
                "departure": "2026-06-01T18:31:00+0200",
                "delay_minutes": 5
            },
            {
                "to": "Unterzollikofen",
                "line": "S 9",
                "arrival": null,
                "operator": "RBS",
                "platform": "22",
                "departure": "2026-06-01T18:31:00+0200",
                "delay_minu
…(truncated, see openapi.json for full schema)
```

### Meta

#### `GET /v1/meta` — Usage notes

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/swisstransit-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "note": "Switzerland's complete public-transport timetable — trains (SBB/CFF/FFS), trams, buses, postbuses, boats, funiculars and cable cars. /v1/locations?query=Zürich = find stops, stations and addresses with their id and coordinates; /v1/connections?from=Zürich&to=Bern = plan a door-to-door journey (optional via, date as YYYY-MM-DD, time as HH:MM, arrival=true to search by arrival time) returning each option's departure & arrival times and platforms, total duration in minutes, number of transfers, the transport products used (e.g. IC 8) and the leg-by-leg breakdown including walking sections; /v1/stationboard?station=Bern (type=departure|arrival) = the live board for a station — line, destination, time, platform and any delay. Place names accept stop names or station ids from /v1/locations. Times include live delays where available. Data from transport.opendata.ch (Swiss open transport data). Covers Switzerland and immediate cross-border connections.",
        "source": "Swiss public transport API — transport.opendata.ch (search.ch / Swiss open data)",
        "endpoints": [
            "/v1/locations",
            "/v1/connections",
            "/v1/stationboard",
            "/v1/meta"
        ]
    },
    "meta": {
        "timestamp": "2026-06-01T16:24:05.467Z",
        "request_id": "b7998463-0c50-4754-9900-74b0a2955b35"
    },
    "status": "ok",
    "message": "Meta retrieved",
    "success": true
}
```


---
Marketplace page: https://www.oanor.com/api/swisstransit-api
OpenAPI spec: https://www.oanor.com/api/swisstransit-api/openapi.json
