### Example API Calls for Arrivals Source: https://www.trafiklab.se/api/our-apis/trafiklab-realtime-apis/timetables These examples show how to make API requests to get arrival information. Similar to departures, the first call is for a general area ID lookup, and the second includes a specific time parameter. ```bash https://realtime-api.trafiklab.se/v1/arrivals/740000003?key=API_KEY https://realtime-api.trafiklab.se/v1/arrivals/740000003/2025-04-01T16:00?key=API_KEY ``` -------------------------------- ### Example API Calls for Departures Source: https://www.trafiklab.se/api/our-apis/trafiklab-realtime-apis/timetables These examples demonstrate how to construct API requests to retrieve departure information. The first call fetches departures for a given area ID, while the second includes a specific time for the lookup. ```bash https://realtime-api.trafiklab.se/v1/departures/740000002?key=API_KEY https://realtime-api.trafiklab.se/v1/departures/740000002/2025-04-01T16:00?key=API_KEY ``` -------------------------------- ### Example API Call: List All Stops Source: https://www.trafiklab.se/api/our-apis/trafiklab-realtime-apis/stop-lookup An example of how to call the 'List all stops' endpoint. Replace '{API_KEY}' with your actual API key to retrieve all stops. ```HTTP https://realtime-api.trafiklab.se/v1/stops/list?key=API_KEY ``` -------------------------------- ### GTFS Feed Info Example Source: https://www.trafiklab.se/api/gtfs-datasets/overview/static-data Example data for the feed_info.txt file, which contains metadata about the GTFS feed. This includes feed ID, publisher information, language, and version. ```csv feed_id,feed_publisher_name,feed_publisher_url,feed_lang,feed_version SE-sj,Samtrafiken i Sverige AB,https://www.samtrafiken.se,sv,2025-02-27 ``` -------------------------------- ### GTFS Agency Data Example Source: https://www.trafiklab.se/api/gtfs-datasets/overview/static-data Example data for the agency.txt file, which describes the transit agencies providing data. It includes agency ID, name, URL, timezone, and language. ```csv agency_id,agency_name,agency_url,agency_timezone,agency_lang 141010000000001418,Västtrafik,https://www.resrobot.se/,Europe/Stockholm,sv 141010000000001001,Västtrafik Göteborgsområdet AB Lokaltrafik AB,https://www.resrobot.se/,Europe/Stockholm,sv 141010000651668112,MTR Express (Sweden) AB,https://www.resrobot.se/,Europe/Stockholm,sv 141010000452254130,Öresundståg,https://www.resrobot.se/,Europe/Stockholm,sv ``` -------------------------------- ### Get Arrivals at Göteborg Central Station (XML) Source: https://www.trafiklab.se/api/our-apis/resrobot-v21/timetables This example shows how to retrieve arrival information at Göteborg Central Station in XML format. It requires a valid API key and the stop ID. The response includes a list of upcoming arrivals. ```http https://api.resrobot.se/v2.1/arrivalBoard?id=740000002&format=xml&accessId=API_KEY ``` -------------------------------- ### API Response: Stop Lookup Example with System Messages Source: https://www.trafiklab.se/api/our-apis/sl/journey-planner-2 This JSON example shows a 'stop lookup' response. It includes 'systemMessages' which might contain errors even if the request was successful, and a list of 'locations' with details like ID, name, coordinates, and parent locality. The 'matchQuality' indicates the relevance of the found stop. ```json { "systemMessages": [ { "type": "error", "module": "BROKER", "code": -8011, "text": "" } ], "locations": [ { "id": "9091001000001079", "isGlobalId": true, "name": "Stockholm, Stockholm Odenplan", "disassembledName": "Stockholm Odenplan", "coord": [ 59.343116, 18.04569 ], "type": "stop", "matchQuality": 948, "isBest": false, "productClasses": [ 0, 2, 5 ], "parent": { "id": "placeID:33001080:1", "name": "Stockholm", "type": "locality" }, "properties": { "stopId": "18001079", "mainLocality": "Stockholm" } }, { "id": "9091001000009117", "isGlobalId": true, "name": "Stockholm, Odenplan", "disassembledName": "Odenplan", "coord": [ 59.342906, 18.049103 ], "type": "stop", "matchQuality": 1000, "isBest": true, "productClasses": [ 0, 2, 5 ], "parent": { "id": "placeID:33001080:1", "name": "Stockholm", "type": "locality" }, "properties": { "stopId": "18009117", "mainLocality": "Stockholm" } } ] } ``` -------------------------------- ### Example transfers.txt Data Source: https://www.trafiklab.se/api/gtfs-datasets/overview/static-data This snippet shows an example of the CSV formatted data found in the transfers.txt file. It includes headers and sample data rows, illustrating how transfer information is structured. ```csv from_stop_id,to_stop_id,transfer_type,min_transfer_time,from_trip_id,to_trip_id 9022014061616002,9022014061616002,1,,141010000981658971,141010000967489295 9022014080420002,9022014080420002,1,,141010000981659030,141010000981658971 9022014080437002,9022014080437002,1,,141010000981659030,141010000981664702 9022014080437002,9022014080437002,1,,141010000981659030,141010000981664817 ``` -------------------------------- ### Example API Call: List Stops by Name Source: https://www.trafiklab.se/api/our-apis/trafiklab-realtime-apis/stop-lookup An example of how to call the 'List stops by name' endpoint. Replace '{API_KEY}' with your actual API key and 'sto' with your desired search term. ```HTTP https://realtime-api.trafiklab.se/v1/stops/name/sto/?key=API_KEY ``` -------------------------------- ### GTFS Route Data Example Source: https://www.trafiklab.se/api/gtfs-datasets/overview/static-data Example data for the routes.txt file, which defines the transit routes. It includes route ID, agency ID, short and long names, and route type. ```csv route_id,agency_id,route_short_name,route_long_name,route_type 90110142802000000,141010000000001418,302,,717 90110143741000000,141010000000001418,420,,717 90110144711000000,141010000000001418,711,,700 90110146304000000,141010000000001418,304,,700 ``` -------------------------------- ### Get Arrivals at Göteborg Central Station (JSON) Source: https://www.trafiklab.se/api/our-apis/resrobot-v21/timetables This example demonstrates how to retrieve arrival information at Göteborg Central Station in JSON format. It requires a valid API key and the stop ID. The response includes a list of upcoming arrivals. ```http https://api.resrobot.se/v2.1/arrivalBoard?id=740000002&format=json&accessId=API_KEY ``` -------------------------------- ### ResRobot Deep Link Request Examples Source: https://www.trafiklab.se/api/our-apis/resrobot-v21/deep-links Examples of constructing ResRobot deep links for route planning. These links can be used to redirect users directly to search results based on specified origin and destination stops or coordinates. ```url https://reseplanerare.resrobot.se/bin/query.exe/sn?&S=740000044&Z=740000001&start=1 ``` ```url https://reseplanerare.resrobot.se/bin/query.exe/sn?&SID=A=16@X=17703271@Y=59869065@O=Uppsala&Z=740000001&time=12:00×el=arrive&start=1 ``` -------------------------------- ### GET /websites/trafiklab_se_api Source: https://www.trafiklab.se/api/our-apis/trafiklab-realtime-apis/timetables Retrieves real-time public transport departures and arrivals for a specified stop. The response includes timestamp, query details, stop information, and a list of departures/arrivals within the next 60 minutes. ```APIDOC ## GET /websites/trafiklab_se_api ### Description Retrieves real-time public transport departures and arrivals for a specified stop. The response includes timestamp, query details, stop information, and a list of departures/arrivals within the next 60 minutes. ### Method GET ### Endpoint /websites/trafiklab_se_api ### Parameters #### Query Parameters - **stop_id** (string) - Required - The ID of the public transport stop to query. - **time** (string) - Optional - The time for which to retrieve departures/arrivals (e.g., '2025-04-01T14:22:00'). Defaults to the current time. ### Request Example ``` GET /websites/trafiklab_se_api?stop_id=71314&time=2025-04-01T14:22:00 ``` ### Response #### Success Response (200) - **timestamp** (string) - The timestamp at which the response was created. - **query** (object) - Information about the query. - **queryTime** (string) - The time specified in the query. - **query** (string) - The stop ID that was queried. - **stops** (array) - Information about the stops included in the response. - **id** (string) - The unique identifier for the stop. - **name** (string) - The name of the stop. - **lat** (number) - The latitude of the stop. - **lon** (number) - The longitude of the stop. - **transport_modes** (array) - A list of transport modes available at the stop. - **alerts** (array) - A list of any alerts associated with the stop. - **departures** (array) - A list of upcoming departures from the queried stop. - **scheduled** (string) - The scheduled departure time. - **realtime** (string) - The real-time departure time. - **delay** (integer) - The delay in minutes. - **canceled** (boolean) - Indicates if the departure is canceled. - **route** (object) - Information about the route. - **name** (string) - The name of the route. - **designation** (string) - The route designation. - **transport_mode_code** (integer) - The code for the transport mode. - **transport_mode** (string) - The type of transport mode. - **direction** (string) - The direction of the route. - **origin** (object) - The origin stop of the route. - **destination** (object) - The destination stop of the route. - **trip** (object) - Information about the specific trip. - **trip_id** (string) - The unique identifier for the trip. - **start_date** (string) - The start date of the trip. - **technical_number** (integer) - The technical number of the trip. - **agency** (object) - Information about the transport agency. - **id** (string) - The unique identifier for the agency. - **name** (string) - The name of the agency. - **operator** (string) - The operator of the service. - **stop** (object) - Information about the departure stop. - **id** (string) - The unique identifier for the stop. - **name** (string) - The name of the stop. - **lat** (number) - The latitude of the stop. - **lon** (number) - The longitude of the stop. - **scheduled_platform** (object) - The scheduled platform information. - **id** (string) - The unique identifier for the platform. - **designation** (string) - The platform designation. - **realtime_platform** (object) - The real-time platform information. - **id** (string) - The unique identifier for the platform. - **designation** (string) - The platform designation. - **alerts** (array) - A list of any alerts associated with the departure. - **is_realtime** (boolean) - Indicates if the departure information is real-time. - **arrivals** (array) - A list of upcoming arrivals at the queried stop (structure similar to departures). #### Response Example ```json { "timestamp": "2025-04-01T14:22:43", "query": { "queryTime": "2025-04-01T14:22:00", "query": "740000002" }, "stops": [ { "id": "71314", "name": "Göteborg C", "lat": 57.708918, "lon": 11.973946, "transport_modes": [ "TRAIN" ], "alerts": [] } ], "departures": [ { "scheduled": "2025-04-01T14:30:00", "realtime": "2025-04-01T14:30:00", "delay": 0, "canceled": false, "route": { "name": "Västtågen", "designation": "3258", "transport_mode_code": 100, "transport_mode": "TRAIN", "direction": "Vänersborg", "origin": { "id": "2", "name": "Göteborg Centralstation" }, "destination": { "id": "241", "name": "Vänersborg central" } }, "trip": { "trip_id": "141010001327690347", "start_date": "2025-04-01", "technical_number": 130 }, "agency": { "id": "505000000000000014", "name": "Västtrafik", "operator": "SJ Götalandståg" }, "stop": { "id": "2", "name": "Göteborg Centralstation", "lat": 57.709299, "lon": 11.973659 }, "scheduled_platform": { "id": "9022050000002017", "designation": "9" }, "realtime_platform": { "id": "9022050000002017", "designation": "9" }, "alerts": [], "is_realtime": false } ], "arrivals": [] } ``` ``` -------------------------------- ### Trafiklab Trips API Request Example Source: https://www.trafiklab.se/api/our-apis/trafiklab-realtime-apis/trip-details This snippet demonstrates how to construct a request to the Trafiklab Trips API. It requires a trip ID, a start date in YYYY-MM-DD format, and an API key. The example shows a specific call for Skånetrafikens bus 3 on November 11th, 2025. ```HTTP https://realtime-api.trafiklab.se/v1/trips/121120000386193630/2025-11-11?key=API_KEY ``` -------------------------------- ### API Response: Journey Planner Example Source: https://www.trafiklab.se/api/our-apis/sl/journey-planner-2 This JSON demonstrates a 'journey planner' response. It contains an empty 'systemMessages' array and a 'journeys' array, where each journey object details trip information, duration, and a list of 'legs'. Each leg specifies origin and destination points with coordinates, departure/arrival times, and associated transport details. ```json { "systemMessages": [ ], "journeys": [ { "tripId": "9015001001812227|9025001000001861|2025-04-04T10:32:42Z|9025001000001011|2025-04-04T10:49:30Z", "tripParams": "maxLengthBicycle=4000&minLengthBicycle=0&mustExcl=1&mustExclOP=sam%3A%3A&name_destination=9091001000009192&name_origin=9091001000009182&selOP=1&type_destination=any&type_origin=any", "tripDuration": 1008, "tripRtDuration": 942, "rating": 0, "isAdditional": false, "interchanges": 0, "legs": [ { "infos": [ ], "duration": 942, "origin": { "isGlobalId": true, "id": "9025001000001861", "name": "Hökarängen, Stockholm", "disassembledName": "1", "type": "platform", "coord": [ 59.257932, 18.082494 ], "niveau": 0, "parent": { "isGlobalId": true, "id": "9021001001861000", "name": "Hökarängen, Stockholm", "disassembledName": "Hökarängen", "type": "stop", "parent": { "id": "placeID:33001080:1", "name": "Stockholm", "type": "locality" }, "properties": { "stopId": "18001861" }, "coord": [ 59.257928, 18.082503 ], "niveau": 0 }, "productClasses": [ 2 ], "departureTimeBaseTimetable": "2025-04-04T10:32:42Z", "departureTimePlanned": "2025-04-04T10:32:42Z", "departureTimeEstimated": "2025-04-04T10:33:06Z", "properties": { "AREA_NIVEAU_DIVA": "0", "area": "1", "platform": "1", "stoppingPointPlanned": "1", "platformName": "1" } }, "destination": { "isGlobalId": true, "id": "9025001000001011", "name": "Slussen, Stockholm", "disassembledName": "1", "type": "platform", "coord": [ 59.319633, 18.072226 ], "niveau": 0, "parent": { "isGlobalId": true, "id": "9021001001011000", "name": "Slussen, Stockholm", "disassembledName": "Slussen", "type": "stop", "parent": { "id": "placeID:33001080:1", "name": "Stockholm", "type": "locality" }, "properties": { "stopId": "18001011" }, "coord": [ 59.319633, 18.072226 ], "niveau": 0 }, "productClasses": [ 2 ], "arrival_time_base_timetable": "2025-04-04T10:49:30Z", "arrival_time_planned": "2025-04-04T10:49:30Z", "arrival_time_estimated": "2025-04-04T10:48:42Z", "properties": { "AREA_NIVEAU_DIVA": "0", "area": "1", "platform": "1", "stoppingPointPlanned": "1", "platformName": "1" } } } ] } ] } ``` -------------------------------- ### Subscribe to Real-time Train Positions via WebSocket Source: https://www.trafiklab.se/api/our-apis/oxyfi Connect to the Trainpos API WebSocket to receive real-time train position updates. This example demonstrates how to establish a connection and handle incoming messages. Ensure you replace 'YOUR-KEY-HERE' with your actual API key. The API key is valid for one subscriber at a time; subsequent connections with the same key will close the previous one. ```python import websocket def on_message(ws, message): print(message) ws = websocket.WebSocketApp("wss://api.oxyfi.com/trainpos/listen?v=1&key=YOUR-KEY-HERE", on_message=on_message) ws.run_forever() ``` ```javascript // Uses https://github.com/websockets/ws const WebSocket = require('ws'); const ws = new WebSocket('wss://api.oxyfi.com/trainpos/listen?v=1&key=YOUR-KEY-HERE'); ws.on('message', function incoming(data) { console.log(data); }); ``` -------------------------------- ### System Info API Source: https://www.trafiklab.se/api/our-apis/sl/journey-planner-2 Retrieve system information for the SL Journey Planner API. ```APIDOC ## GET /v2/system-info ### Description Retrieves system information for the SL Journey Planner API. ### Method GET ### Endpoint https://journeyplanner.integration.sl.se/v2/system-info ### Parameters #### Query Parameters None ### Request Example None ### Response #### Success Response (200) - **data** (object) - Contains system information. #### Response Example ```json { "data": { "version": "1.0", "next_check": "2024-08-01T10:00:00Z" } } ``` ``` -------------------------------- ### Get Departures from Göteborg Central Station (XML) Source: https://www.trafiklab.se/api/our-apis/resrobot-v21/timetables This example shows how to retrieve departure information from Göteborg Central Station in XML format. It requires a valid API key and the stop ID. The response includes a list of upcoming departures. ```http https://api.resrobot.se/v2.1/departureBoard?id=740000002&format=xml&accessId=API_KEY ``` -------------------------------- ### Get Departures from Göteborg Central Station (JSON) Source: https://www.trafiklab.se/api/our-apis/resrobot-v21/timetables This example demonstrates how to retrieve departure information from Göteborg Central Station in JSON format. It requires a valid API key and the stop ID. The response includes a list of upcoming departures. ```http https://api.resrobot.se/v2.1/departureBoard?id=740000002&format=json&accessId=API_KEY ``` -------------------------------- ### Example JSON Response for Departures from a Site Source: https://www.trafiklab.se/api/our-apis/sl/transport This JSON structure outlines departure information for public transport. It includes details such as the direction of travel, destination, and the scheduled departure time. The 'state' field indicates the current status of the departure, such as 'NOTEXPECTED'. This response is crucial for real-time journey planning. ```json { "departures": [ { "direction": "string", "direction_code": 2, "via": "string", "destination": "string", "state": "NOTEXPECTED", "scheduled": "2024-01-01T01:00:00" } ] } ``` -------------------------------- ### System Info API Source: https://www.trafiklab.se/api/our-apis/sl/journey-planner-2 Retrieve the accessible date period for route planning. ```APIDOC ## GET /system-info ### Description Retrieve the accessible date period for route planning. ### Method GET ### Endpoint /system-info ### Parameters #### Query Parameters None ### Request Example ``` GET /system-info HTTP/1.1 Host: journeyplanner.integration.sl.se ``` ### Response #### Success Response (200) - **validity** (object) - Information about the validity period. - **systemMessages** (array) - An array of system messages. #### Response Example ```json { "validity": { "from": "2023-01-01T00:00:00", "to": "2023-12-31T23:59:59" }, "systemMessages": [ { "id": "123", "text": "Planned maintenance on Saturday.", "type": "INFO", "useEffectDate": "2023-10-28T00:00:00" } ] } ``` ``` -------------------------------- ### ResRobot Deep Link Response Example (HTML Redirect) Source: https://www.trafiklab.se/api/our-apis/resrobot-v21/deep-links An example of the HTML response received from the ResRobot Deep Links API. This response contains a meta-refresh tag and a JavaScript redirect to the ResRobot journey planner page with pre-filled search parameters. ```html The journey planner moved to a new url.
Click here to start the journey planner ``` -------------------------------- ### Arrival Board API Source: https://www.trafiklab.se/api/our-apis/trafiklab-realtime-apis/openapi-specification Retrieve real-time arrival information for a specific stop, either currently or at a specified date and time. ```APIDOC ## Arrival Board API ### Description Retrieve real-time arrival information for a specific stop, either currently or at a specified date and time. ### Method GET ### Endpoint /arrivals/{stopId} ### Parameters #### Path Parameters - **stopId** (string) - Required - The ID of the stop to retrieve arrivals for. ### Description Get Arrival Information (Current) ### Method GET ### Endpoint /arrivals/{stopId}/{dateTime} ### Parameters #### Path Parameters - **stopId** (string) - Required - The ID of the stop to retrieve arrivals for. - **dateTime** (string) - Required - The specific date and time to retrieve arrivals for (ISO 8601 format). ### Description Get Arrival Information (Specific Time) ### Response #### Success Response (200) - **ArrivalsResponse** (object) - A response object containing arrival information. #### Response Example ```json { "arrivals": [ { "stopAreaName": "Stockholm Centralstation", "stopAreaId": "9111", "stopPointName": "Stockholm C", "stopPointId": "9111", "dateTime": "2023-10-27T10:45:00", "date": "2023-10-27", "stopAreaType": "MUNICIPALITY", "transportMode": "TRAIN", "routeIdx": "67890", "directionText": "from Uppsala", "name": "Tåg 123", "destination": "Stockholm C", "secondaryDestination": null, "foregroundColor": "#FFFFFF", "backgroundColor": "#000000", "obligatory": false, "order": 1, "platform": "12", "realTime": true, "deviation": null, "lastUpdated": "2023-10-27T10:40:00" } ] } ``` ``` -------------------------------- ### Constructing a POST Request for Trafikverket API Source: https://www.trafiklab.se/api/other-apis/trafikverket This example demonstrates the structure of a POST request to the Trafikverket Open API. It includes authentication details, the desired object type, schema version, a limit for results, and filtering criteria. The response format (JSON or XML) depends on the URL suffix. ```xml ``` -------------------------------- ### Download Extra GTFS Files Source: https://www.trafiklab.se/api/trafiklab-apis/gtfs-regional Retrieve extra GTFS files by appending '__extra_' to the standard GTFS zip file name. These files require an API key and count towards the same quota as static GTFS data. ```APIDOC ## GET /gtfs/{operator}/{operator}_extra.zip ### Description Fetches extra GTFS files which contain additional information linking GTFS data to internal operator systems. These files are not part of the GTFS standard but are crucial for data integration. ### Method GET ### Endpoint https://opendata.samtrafiken.se/gtfs/{operator}/{operator}_extra.zip?key={apikey} ### Parameters #### Path Parameters - **operator** (string) - Required - The abbreviation of the operator for whom to download the extra GTFS files. #### Query Parameters - **key** (string) - Required - Your API key for authentication. ### Request Example ``` https://opendata.samtrafiken.se/gtfs/sl/sl_extra.zip?key=YOUR_API_KEY ``` ### Response #### Success Response (200) - **file** (zip) - The extra GTFS data in zip format. #### Response Example (Binary data representing a zip file) ``` -------------------------------- ### SL Deviations API Example Response Source: https://www.trafiklab.se/api/our-apis/sl/deviations An example of the JSON response structure from the SL Deviations API. It includes details about deviations, such as their ID, publication times, priority levels, messages in different languages, and affected lines and stop areas. This response format is used for all successful API calls. ```json [ { "version": 1, "created": "2022-03-03T19:03:48.713+01:00", "modified": "2022-03-03T19:03:48.713+01:00", "deviation_case_id": 52432153, "publish": { "from": "2022-03-03T19:03:48.700+01:00", "upto": "2022-03-03T20:03:00.000+01:00" }, "priority": { "importance_level": 2, "influence_level": 3, "urgency_level": 1 }, "message_variants": [ { "header": "Entré vid Medborgarplatsen stängd", "details": "Vid Medborgarplatsen är entrén från Folkungagatan stängd på grund av underhållsarbete.", "scope_alias": "tunnelbanans röda linje 13", "weblink": "https://sl.se", "language": "sv" } ], "scope": { "stop_areas": [ { "id": 1511, "transport_authority": 1, "name": "Medborgarplatsen", "type": "METROSTN", "stop_points": [ { "id": 222, "name": "Norrö" } ] } ], "lines": [ { "id": 17, "transport_authority": 1, "designation": "17", "transport_mode": "METRO", "name": "Gröna linjen", "group_of_lines": "Tunnelbanans gröna linje" } ] } } ] ``` -------------------------------- ### GET /netex/{operator}/{operator}.zip Source: https://www.trafiklab.se/api/netex-datasets/netex-regional/netex-regional-specification Obtain a static NeTEx dataset for a specified operator. ```APIDOC ## GET /netex/{operator}/{operator}.zip ### Description Obtain a static NeTEx dataset for a specified operator. ### Method GET ### Endpoint /netex/{operator}/{operator}.zip ### Parameters #### Path Parameters - **operator** (string) - Required - The operator identifier for which to fetch the NeTEx dataset. ### Request Example (No request body for GET requests) ### Response #### Success Response (200) - **file** (zip) - The NeTEx dataset in zip format. #### Response Example (Binary data - zip file content) ``` -------------------------------- ### Extra Files Source: https://www.trafiklab.se/api/gtfs-datasets/gtfs-sweden Download extra files that provide additional information to link GTFS files with internal operator systems. These files use the same API key as static data and count against the same quota. ```APIDOC ## Extra Files ### Description Download extra files that provide additional information to link GTFS files with internal operator systems. These files use the same API key as static data and count against the same quota. ### Method GET ### Endpoint `https://opendata.samtrafiken.se/gtfs-sweden/sweden_extra.zip?key={apikey}` ### Parameters #### Query Parameters - **key** (string) - Required - Your personal API key. ### Request Example (No request body for GET requests) ### Response #### Success Response (200) - The response will be a zip file containing extra data. #### Response Example (Binary data, not representable as JSON) ```