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