Transport

Swiss public transport API

Introduction

The Transport API allows interested developers to build their own applications using public timetable data, whether they're on the web, the desktop or mobile devices. The aim of the API is to cover public transport within Switzerland. Find out more about how you can start exploring the timetable data playground or just browse the API Documentation.

The source code can be found on GitHub, please ask any technical questions there. If you need a direct contact write a mail to transport@opendata.ch.

Examples

A few examples to show what can be produced with the Transport API:

API Documentation

Rate Limiting

The number of HTTP requests you can send to transport.opendata.ch is limited to 300 requests per minute per IP address. The number of remaining requests is sent back for your information in the HTTP response header X-Rate-Limit-Remaining. If you reach the maximum number of requests please contact us, we are eager to hear your use case and discuss a solution.

API Resources

The Transport API builds on REST style resources which respond in JSON. Individual resources are detailed below. Cross Origin Resource Sharing (CORS) is enabled, so you can easily use the API on transport.opendata.ch from any website (avoid setting custom headers though).


/locations

Returns the matching locations for the given parameters. Either query or ( x and y ) are required.

The locations in the response are scored to determine which is the most exact location.

This method can return a refine response, what means that the request has to be redone.

Resource URL

http://transport.opendata.ch/v1/locations

Request Parameters

Name Required Description Example
query optional Specifies the location name to search for Basel
x optional Latitude 47.476001
y optional Longitude 8.306130
type optional Specifies the location type, possible types are:
  • all (default): Looks up for all types of locations
  • station: Looks up for stations (train station, bus station)
  • poi: Looks up for points of interest (Clock tower, China garden)
  • address: Looks up for an address (Zurich Bahnhofstrasse 33)
address

Response parameters

Name Description
stations A list of locations

Example Request

GET http://transport.opendata.ch/v1/locations?query=Basel

Example response

{
    "stations": [
        {
            "coordinate": {
                "type": "WGS84",
                "x": "8540192",
                "y": "47378177"
            },
            "id": "008503000",
            "name": "Zuerich",
            "score": "100"
        },
        {
            "coordinate": {
                "type": "WGS84",
                "x": "8540192",
                "y": "47378177"
            },
            "id": "008503000",
            "name": "Zurich",
            "score": "99"
        }
    ]
}
            

/connections

Returns the next connections from a location to another.

Resource URL

http://transport.opendata.ch/v1/connections

Request Parameters

Name Required Description Example
from required Specifies the departure location of the connection Lausanne
to required Specifies the arrival location of the connection Genève
via optional Specifies up to five via locations. When specifying several vias, array notation (via[]=via1&via[]=via2) is required. Bern
date optional Date of the connection, in the format YYYY-MM-DD 2012-03-25
time optional Time of the connection, in the format hh:mm 17:30
isArrivalTime optional defaults to 0, if set to 1 the passed date and time is the arrival time 1
transportations optional Transportation means; one or more of ice_tgv_rj, ec_ic, ir, re_d, ship, s_sn_r, bus, cableway, arz_ext, tramway_underground transportations[]=ec_ic&
transportations[]=bus
limit optional 1 - 6. Specifies the number of connections to return. If several connections depart at the same time they are counted as 1. 4
page optional 0 - 10. Allows pagination of connections. Zero-based, so first page is 0, second is 1, third is 2 and so on. 3
direct optional defaults to 0, if set to 1 only direct connections are allowed 1
sleeper optional defaults to 0, if set to 1 only night trains containing beds are allowed, implies direct=1 1
couchette optional defaults to 0, if set to 1 only night trains containing couchettes are allowed, implies direct=1 1
bike optional defaults to 0, if set to 1 only trains allowing the transport of bicycles are allowed 1

Response parameters

Name Description
connections A list of connections

Example Requests

GET http://transport.opendata.ch/v1/connections?from=Lausanne&to=Genève

which is the same as

GET http://transport.opendata.ch/v1/connections?from=008501120&to=008501008

Example response

{
    "connections" : [
        {
            "from" : {
                "arrival" : null,
                "arrivalTimestamp" : null,
                "departure" : "2012-03-31T08:58:00+02:00",
                "departureTimestamp" : 1333177080,
                "platform" : "7",
                "prognosis" : {
                    "platform" : null,
                    "arrival" : null
                    "departure" : null
                    "capacity1st" : "-1",
                    "capacity2nd" : "-1",
                },
                "station" : {
                    "coordinate" : {
                        "type" : "WGS84",
                        "x" : "6629086",
                        "y" : "46516785"
                    },
                    "id" : "008501120",
                    "name" : "Lausanne",
                    "score" : null
                }
            },
            "to" : {
                "arrival" : "2012-03-31T09:46:00+02:00",
                "arrivalTimestamp" : 1333179960,
                "departure" : null,
                "departureTimestamp" : null,
                "platform" : "2",
                "prognosis" : {
                    "platform" : null,
                    "arrival" : null,
                    "departure" : null
                    "capacity1st" : null,
                    "capacity2nd" : null,
                },
                "station" : {
                    "coordinate" : {
                        "type" : "WGS84",
                        "x" : "6142437",
                        "y" : "46210217"
                    },
                    "id" : "008501008",
                    "name" : "Genève",
                    "score" : null
                }
            }
        },
    ],
    // ...
}
            

/stationboard

Returns the next connections leaving from a specific location.

Resource URL

http://transport.opendata.ch/v1/stationboard

Request Parameters

Name Required Description Example
station required Specifies the location of which a stationboard should be returned Aarau
id optional The id of the station whose stationboard should be returned.
Alternative to the station parameter; one of these two is required.
If both an id and a station are specified the id has precedence.
8503059 (for Zurich Stadelhofen)
limit optional Number of departing connections to return.
This is not a hard limit - if multiple connections leave at the same time it'll return any connections that leave at the same time as the last connection within the limit.
For example: limit=4 will return connections leaving at :
  • 19:30
  • 19:32
  • 19:32
  • 19:35
  • 19:35
Because one of the connections leaving at 19:35 is within the limit, all connections leaving at 19:35 are shown.
15
transportations optional Transportation means; one or more of ice_tgv_rj, ec_ic, ir, re_d, ship, s_sn_r, bus, cableway, arz_ext, tramway_underground ?transportations[]=ec_ic&transportations[]=bus
datetime optional Date and time of departing connections, in the format YYYY-MM-DD hh:mm. 2012-03-25 17:30

Response parameters

Name Description
stationboard A list of stops, showing the last stop of the line leaving that station.

Example Requests

GET http://transport.opendata.ch/v1/stationboard?station=Aarau&limit=10

which is the same as

GET http://transport.opendata.ch/v1/stationboard?id=008502113&limit=10

Example response

{
    "stationboard" : [
    {
        "stop":
        {
            "station":
            {
                "id": "8502996",
                "name": "Aarau, Bahnhof",
                "score": null,
                "coordinate":
                {
                    "type" : "WGS84",
                    "x": "8050864",
                    "y": "47392020"
                }
            },
            "arrival": null,
            "arrivalTimestamp": null,
            "departure": "2012-03-31T14:39:00+02:00",
            "departureTimestamp": 1333197540,
            "platform": "",
            "prognosis":
            {
                "platform": null,
                "arrival": null,
                "departure": null,
                "capacity1st": "-1",
                "capacity2nd": "-1"
            }
        },
        "name": "BUS13543",
        "category": "BUS",
        "number": "13543",
        "operator": null,
        "to": "Frick, Bahnhof"
    },{
        "stop":
        {
            "station":
            {
                "id": "8502996",
                "name": "Aarau, Bahnhof",
                "score": null,
                "coordinate":
                {
                    "type": "WGS84",
                    "x": "8050864",
                    "y": "47392020"
                }
            },
            "arrival": null,
            "arrivalTimestamp": null,
            "departure": "2012-03-31T14:39:00+02:00",
            "departureTimestamp": 1333197540,
            "platform": "",
            "prognosis":
            {
                "platform": null,
                "arrival": null,
                "departure": null,
                "capacity1st": "-1",
                "capacity2nd": "-1"
            }
        },
        "name": "Bus 2",
        "category": "Bus",
        "number": "2",
        "operator": "BBA",
        "to": "Aarau Rohr, Unterdorf"
    },
    // ...
    ]
}
            

API Objects

API responses are composites of the following objects:

Location Object

Name Description
id The id of the location
type Type of the location, can contain:
  • station: Location is a train station, bus station
  • poi: Location is a point of interest (Clock tower, China garden)
  • address: Location is an address
  • refine: Location is not defined, the user has to relocate
name The location name
score The accuracy of the result
coordinates The location coordinates
distance If search has been with coordinates, distance to original point in meters

Coordinates Object

Name Description
type The type of the given coordinate
x Latitude
y Longitude

Connection Object

A connection represents a possible journey between two locations.

Name Description Example
from The departure checkpoint of the connection
to The arrival checkpoint of the connection
duration Duration of the journey 00d00:43:00
service Service information about how regular the connection operates
products Array with transport products IR, S9
capacity1st The maximum estimated occupation load of 1st class coaches 1
capacity2st The maximum estimated occupation load of 2nd class coaches 2
sections A list of sections

Checkpoint Object

A checkpoint represents an arrival or a departure point (in time and space) of a connection.

Name Description Example
station The location of the checkpoint
arrival The arrival time to the checkpoint 14:58:00
departure The departure time from the checkpoint null
platform The arrival/departure platform 8
prognosis The checkpoint prognosis

Service Object

Operation information for a connection.

Name Description Example
regular Information about how regular a connection operates. daily
irregular Additional information about irregular operation dates. not 23., 24. Jun 2012

Prognosis Object

A prognosis contains "realtime" informations on the status of a connection checkpoint.

Name Description Example
platform The estimated arrival/departure platform 8
departure The departure time prognosis to the checkpoint
Date format: ISO 8601
2012-03-31T08:58:00+02:00
arrival The arrival time prognosis to the checkpoint
Date format: ISO 8601
2012-03-31T09:35:00+02:00
capacity1st The estimated occupation load of 1st class coaches 1
capacity2st The estimated occupation load of 2nd class coaches 2

Stop Object

Name Description Example
station A location object showing this line's stop at the requested station.
name The name of the connection Bus 2
category The type of connection this is Bus
number The number of the connection's line, e.g. Bus line 2 2
operator The operator of the connection's line BBA
to The final destination of this line Aarau Rohr, Unterdorf

Section Object

A connection consists of one or multiple sections.

Name Description Example
journey A journey, the transportation used by this section. Can be null
walk Information about walking distance, if available null
departure The departure checkpoint of the connection
arrival The arrival checkpoint of the connection

Journey Object

The actual transportation of a section, e.g. a bus or a train between two stations.

Name Description Example
name The name of the transportation ICN 518
category Category of the transportation ICN
categoryCode An internal category code of the transportation 1
number The number of the transportation line 518
operator The company performing the transportation 8
to Final destination of the train Zürich HB
passList Checkpoints the train passed on the journey
capacity1st The maximum estimated occupation load of 1st class coaches 1
capacity2st The maximum estimated occupation load of 2nd class coaches 2

Limit response

You can limit the response data with the fields parameter. If any fields[] is passed, only the specified fields are in the response. The API is aware of the hierarchy, if you set a field, everything below is in the response unless a more specific (further down in the hierarchy) field is set.

Example Request

GET http://transport.opendata.ch/v1/connections?from=Lausanne&to=Genève&fields[]=connections/from/departure&fields[]=connections/to/arrival

Example response

{
    "connections":[
        {
            "from":{
                "departure":"2012-05-01T19:42:00+0200",
            },
            "to":{
                "arrival":"2012-05-01T20:15:00+0200",
            }
        },
    ],
    //....
}

            

Example Request

GET http://transport.opendata.ch/v1/connections?from=Lausanne&to=Genève&fields[]=connections/from&fields[]=connections/to/station

Example response

            
{
    "connections":[
        {
            "from":{
                "station":{
                    "id":"008501120",
                    "name":"Lausanne",
                    "score":null,
                    "coordinate":{
                        "type":"WGS84",
                        "x":6.629086,
                        "y":46.516785
                    }
                },
                "arrival":null,
                "arrivalTimestamp":null,
                "departure":"2012-05-01T19:42:00+0200",
                "departureTimestamp":1335894120,
                "platform":"5",
                "prognosis":{
                    "platform":null,
                    "arrival":null,
                    "departure":null,
                    "capacity1st":"1",
                    "capacity2nd":"1"
                }
            },
            "to":{
                "station":{
                    "id":"008501008",
                    "name":"Gen\u00e8ve",
                    "score":null,
                    "coordinate":{
                        "type":"WGS84",
                        "x":6.142437,
                        "y":46.210217
                    }
                }
            }
        },
    ],
    // ...
}