If you are not yet familiar with GraphQL and GraphiQL it is highly recommended to review those pages at first.
Term | Explanation |
---|---|
Route | A public transport service shown to customers under a single name, usually from point A to B and back. For example: trams 1 and 1A, buses 18 and 102T, or train A. Commonly used synonym: line |
Pattern | A sequence of stops as used by a specific direction (i.e. inbound or outbound journey) and variant of a route. For example, a variant of a route could be a tram entering service from the depot and joining at the middle of the route or a route might have a short term diversion without changing the route name (longer diversions are usually marked as different routes). |
Trip | A specific occurance of a pattern, usually identified by the route and exact departure time from the first stop. For example: bus 102 leaving from Otaniemi on 2017-11-21 at 10:00, or more generally leaving from Otaniemi at 10:00 on specified days. |
Note: For more details about the query types routes and pattern and their parameters you can use the Documentation Explorer provided in GraphiQL.
Note: If the examples provided with an id or other parameter do not return what is expected then the value in question may not be in use any more and you should try again with an existing value.
{
routes(name: "M42") {
gtfsId
shortName
longName
mode
}
}
{
routes(name: "M14", transportModes: BUS) {
gtfsId
shortName
longName
mode
}
}
{
routes(name: "Tv1", transportModes: TRAM) {
gtfsId
shortName
longName
mode
}
}
{
routes(name: "Tb14") {
shortName
longName
patterns {
code
directionId
name
headsign
}
}
}
Example response:
{
"data": {
"routes": [
{
"shortName": "Tb14",
"longName": "Troleibuz 14",
"patterns": [
{
"code": "stpt:r1006:1:01",
"directionId": 1,
"name": "Tb14 to Gheorghe Barițiu (stpt:s2671)",
"headsign": "Gheorghe Barițiu"
},
{
"code": "stpt:r1006:0:01",
"directionId": 0,
"name": "Tb14 to I.I. de la Brad (stpt:s2793)",
"headsign": "I.I. de la Brad"
}
]
}
]
}
}
See previous example on how to find pattern IDs for a route
code
in a pattern object{
pattern(id: "stpt:r990:0:01") {
name
stops {
name
}
}
}
{
pattern(id: "stpt:r990:0:01") {
code
directionId
name
headsign
trips {
gtfsId
tripHeadsign
routeShortName
directionId
}
}
}
Query type fuzzyTrip can be used to query a trip without its id, if other details uniquely identifying the trip are available
For example, from the following vehicle position message
{
"VP": {
"desi":"550",
"dir":"1",
"oper":12,
"veh":1306,
"tst":"2019-06-28T09:49:01.457Z",
"tsi":1561715341,
"spd":12.29,
"hdg":47,
"lat":60.182376,
"long":24.825781,
"acc":0.44,
"dl":-2,
"odo":24627,
"drst":0,
"oday":"2019-06-28",
"jrn":99,
"line":261,
"start":"11:57",
"loc":"GPS",
"stop":null,
"route":"2550",
"occu":0
}
}
it is possible to parse:
Note:
Vehicle position messages use different direction id than the Routing API
Departure time must be in seconds
11 * 60 * 60 + 57 * 60
= 43020If the date in fields oday
and tst
is not the same and the departure time (start
) is earlier than the time in tst
, add 86400 seconds to departure time
e.g.
tst = 2018-08-16T00:15:00.836Z
(note that this is in UTC time)oday = 2018-08-15
start = 03:10
3 * 60 * 60 + 10 * 60 + 86400
= 97800Due to a bug in the vehicle position API, some route ids don't match the route id in the routing API
null
For example, the following query checks if the vehicle, which sent the vehicle position message above, is wheelchair accessible:
{
fuzzyTrip(route: "stpt:r1558", direction: 0, date: "2019-06-28", time: 43020) {
route {
shortName
}
wheelchairAccessible
}
}