Digitransit APIs require registration. More information
Topics:

Routes

If you are not yet familiar with GraphQL and GraphiQL it is highly recommended to review those pages at first.

Glossary

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: tram 15 leaving from Keilaniemi on 2024-12-18 at 13:13, or more generally leaving from Keilaniemi at 13:13 on specified days.

Query examples

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.

Query all routes where name starts with "10"

  1. Click this link to run the query below in GraphiQL.
{
  routes(name: "10") {
    gtfsId
    shortName
    longName
    mode
  }
}
  1. Press play in GraphiQL to execute the query.

Query all bus routes where name starts with "58"

  1. Click this link to run the query below in GraphiQL.
{
  routes(name: "58", transportModes: BUS) {
    gtfsId
    shortName
    longName
    mode
  }
}
  1. Press play in GraphiQL to execute the query.

Query all tram routes where name starts with "1"

  1. Click this link to run the query below in GraphiQL.
{
  routes(name: "1", transportModes: TRAM) {
    gtfsId
    shortName
    longName
    mode
  }
}
  1. Press play in GraphiQL to execute the query.

Query patterns of a route

  1. Click this link to run the query below in GraphiQL.
{
  routes(name: "59", transportModes: BUS) {
    shortName
    longName
    patterns {
      code
      directionId
      name
      headsign
    }
  }
}
  1. Press play in GraphiQL to execute the query.

Example response:

{
  "data": {
    "routes": [
      {
        "shortName": "59",
        "longName": "Sompasaari-Kalasatama(M)-Pasila-Pajamäki",
        "patterns": [
          {
            "code": "HSL:1059:0:01",
            "directionId": 0,
            "name": "59 to Pajamäki (HSL:1461110)",
            "headsign": "Pajamäki"
          },
          {
            "code": "HSL:1059:1:01",
            "directionId": 1,
            "name": "59 to Polariksenkatu (HSL:1100128)",
            "headsign": "Sompasaari"
          }
        ]
      }
    ]
  }
}

Query stop names by pattern ID

  • See previous example on how to find pattern IDs for a route

    • Pattern ID is value of code in a pattern object
  • Click this link to run the query below in GraphiQL.
{
  pattern(id: "HSL:1059:0:01") {
    name
    stops {
      name
    }
  }
}
  1. Press play in GraphiQL to execute the query.

Query trips of a specific pattern

  1. Click this link to run the query below in GraphiQL.
{
  pattern(id: "HSL:1059:0:01") {
    code
    directionId
    name
    headsign
    trips {
      gtfsId
      tripHeadsign
      routeShortName
      directionId
    }
  }
}
  1. Press play in GraphiQL to execute the query.

Query trip with id

  1. Click this link to run the query below in GraphiQL.
{
  trip(id: "HSL:1020_20240314_Pe_1_0933") {
    tripHeadsign
    occupancy {
      occupancyStatus
    }
  }
}
  1. Press play in GraphiQL to execute the query.

Example response:

{
  "data": {
    "trip": {
      "tripHeadsign": "Munkkivuori",
      "occupancy": {
        "occupancyStatus": "FEW_SEATS_AVAILABLE"
      }
    }
  }
}
© Digitransit 2024