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. 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

API Resources

The Transport API builds on REST style resources which respond in JSON. Individual resources are detailed below.


/locations

Returns the matching locations for the given parameters.

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 required 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
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. Bern
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,
                "departure" : "2012-03-31T08:58:00+02:00",
                "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",
                "departure" : 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

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,
            "departure": "2012-03-31T14:39:00+02:00",
            "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,
            "departure": "2012-03-31T14:39:00+02:00",
            "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 fire
coordinates The location coordinates

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
date The connection date 2012-03-19
from The departure checkpoint of the connection
to The arrival checkpoint of the connection

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

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

Limit response

You can limit the response data with the fields parameter. If any field[] 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":{
                "station":null,
                "arrival":null,
                "departure":"2012-05-01T19:42:00+0200",
                "platform":null,
                "prognosis":null,
            },
            "to":{
                "station":null,
                "arrival":"2012-05-01T20:15:00+0200",
                "departure":null,
                "platform":null,
                "prognosis":null,
            },
            "sections":null
        },
    ],
    //....
}

            

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,
                "departure":"2012-05-01T19:42:00+0200",
                "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
                    }
                },
                "arrival":null,
                "departure":null,
                "platform":null,
                "prognosis":null,
            },
            "sections":null
        },
    ],
    // ...
}
            

Currently, the fields which are not requested get returned with null as value. These fields may get removed from the response in the future, don't rely on them being there.