# Real-Time Data

import { Callout } from 'zudoku/components'

These APIs allow your server to subscribe to real-time data from all included real-time feeds in Norway on SIRI 2.0. It is available as SIRI XML, SIRI Lite (REST) and GTFS-RT.

<Callout type="info">
These services include only real-time data and not any basic journey planner information. If you are creating an end-user service such as a journey planner, the JourneyPlanner API is a better choice.
</Callout>

## Available data streams

| Codespace | Source | SIRI ET | SIRI VM | SIRI SX | GTFS-RT Trip Updates | GTFS-RT Vehicle Positions | GTFS-RT Service Alerts |
|-----------|--------|---------|---------|---------|---------------------|--------------------------|------------------------|
| | Entire Norway | ✓ | ✓ | ✓ | | | |
| AKT | Agder (AKT) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| ATB | Trøndelag (AtB) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| AVI | Avinor | | | | | | |
| BNR | SJ Nord (via Bane Nor) see FLT, GOA and VYG for other railway operators. | ✓ | | | | | |
| BRA | Viken (Brakar) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| FIN | Troms og Finnmark (Snelandia) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| FLT | Flytoget | ✓ | | ✓ | ✓ | ✓ | ✓ |
| GOA | Go-Ahead | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| INN | Innlandet (Innlandstrafikk) | ✓ | ✓ | ✓ | | | |
| KOL | Rogaland (Kolumbus) | ✓ | ✓ | | ✓ | ✓ | |
| MOR | Møre og Romsdal (Fram) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| NBU | Connect Bus Flybuss | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| NOR | Nordland fylkeskommune | ✓ | | ✓ | | | |
| NSB | Vy | ✓ | ✓ | ✓ | | ✓ | |
| OST | Viken (Østfold kollektivtrafikk) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| RUT | Oslo region (Ruter) | ✓ | | ✓ | ✓ | | ✓ |
| SJN | SJ Nord | | | ✓ | | | |
| SKY | Vestland (Skyss) | ✓ | ✓ | ✓ | | | |
| SOF | Vestland (Kringom) | | | ✓ | | | |
| TEL | Vestfold og Telemark (Farte) | | | | ✓ | ✓ | |
| TRO | Troms og Finnmark (Troms fylkestrafikk) | ✓ | ✓ | ✓ | ✓ | ✓ | |
| VKT | Vestfold og Telemark (VKT) | | | ✓ | | | |
| VOT | Vestfold og Telemark | ✓ | ✓ | | ✓ | ✓ | |
| VYB | Vy Buss (SE) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| VYG | Vy Group | ✓ | ✓ | ✓ | | ✓ | |
| VYX | Vy Express |  | ✓ | |  | ✓ | ✓ |

## SIRI

SIRI is a CEN Technical Standard that specifies a European interface standard for exchanging information about the planned, current or projected performance of real-time public transport operations between different computer systems.

### Publish/subscribe

When using `publish/subscribe` you'll first get one (or more) set with initial data, and then continuous updates with changes. This option requires an accessible endpoint which accepts HTTP POST requests from the Entur SIRI service.

### Request/response

For Request/Response, the `<RequestorRef>` attribute is used to track changes and must therefore remain the same for all subsequent requests in order to only get changes. The attribute `MoreData=true` means the data comes in bunches, just like paging, and more data can be fetched immediately after the first "page" is received. Eg. if there are 20,000 objects, these will be split up in smaller parts and repeated requests are needed to get the full set.

### Types of data

#### ET – Estimated Timetable

Real-time estimates for each service journey. Included are planned-, actual- and estimated departure times, cancellations and changes in stop patterns.

#### VM – Vehicle Monitoring

Vehicle-centric real-time data with the position of a vehicle, as well as any deviation from scheduled timetable on a given departure.

#### SX – Situation Exchange

Textual messages displayed to end users. They are always associated with a departure, line, stop etc., or combinations of these.

### SIRI Lite

With simple HTTP GET calls to retrieve data, you can use the `requestorId` URL-parameter to _only_ retrieve changes made since the last time you asked. If you do not use this, you will always get the full dataset, not just the first time you make a request. You must use a unique [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier).

-   Example: https://api.entur.io/realtime/v1/rest/sx?requestorId=757c9284-0f12-4a46-a557-33a19e80119b

### More information

-   SIRI standard: https://transmodel-cen.eu/index.php/siri/
-   Norwegian SIRI-profile: https://enturas.atlassian.net/wiki/spaces/PUBLIC/pages/637370420/Norwegian+SIRI+profile
-   Example SIRI-XML that follow the Norwegian SIRI-profile: https://github.com/entur/profile-norway-examples/tree/master/siri/

## GTFS-RT

GTFS Realtime is a feed specification that allows public transportation agencies to provide realtime updates about their fleet to application developers. It is an extension to GTFS (General Transit Feed Specification), an open data format for public transportation schedules and associated geographic information.

### Request/response

Only supports request/response currently. Endpoints exist for each data type that download the full dataset, filtered by datasource (codespace) if provided. This dataset is updated every 15 seconds. Later we will support publish/subscribe and continuous updates.

-   Example: https://api.entur.io/realtime/v1/gtfs-rt/trip-updates?datasource=RUT

### Types of data

#### Trip updates

Delays, cancellations, changed routes. Similar to SIRI ET.

#### Vehicle positions

Information about the vehicles including location and congestion level. Similar to SIRI VM.

#### Service alerts

Stop moved, unforeseen events affecting a station, route or the entire network. Similar to SIRI SX.

### More information

-   GTFS-RT documentation: https://gtfs.org/documentation/realtime/reference/
-   Trip updates example: https://gtfs.org/documentation/realtime/examples/trip-updates/

## API Reference

### HTTP POST (Standard SIRI 2.0)

Publish/subscribe: https://api.entur.io/realtime/v1/subscribe

Request/Response: https://api.entur.io/realtime/v1/services

Get data for only one operator, add `/<Codespace-ID>` to the end of URL. You can find the operator's Codespace-ID in the list located above.

Example: https://api.entur.io/realtime/v1/services/RUT

### HTTP GET (Standard SIRI 2.0 Lite)

HTTP GET https://api.entur.io/realtime/v1/rest/sx

HTTP GET https://api.entur.io/realtime/v1/rest/vm

HTTP GET https://api.entur.io/realtime/v1/rest/et

**Note:** Limited to 4 requests per minute. If more frequent updates are needed, publish/subscribe should be used.

### Optional HTTP-parameters

#### datasetId

-   E.g. _datasetId=RUT_. You can find the operator's Codespace-ID in the list above.
-   Limits the results to original dataset-provider

Example: https://api.entur.io/realtime/v1/rest/et?datasetId=RUT

#### excludedDatasetIds

-   Comma-separated list of datasets to exclude from result
-   E.g. _excludedDatasetIds=RUT,NSB_
-   Limits result by _excluding_ data from the provided datasetIds
-   _Note:_ Valid for VM and ET requests only
    (I.e. the opposite of parameter `datasetId`)

Example: https://api.entur.io/realtime/v1/rest/et?excludedDatasetIds=BNR,OST,RUT

#### useOriginalId

By default we return data with IDs mapped to those used in the static route data. Instead, if you want the original IDs delivered from the underlying system, you can add a URL parameter useOriginalId = true.

**NB:** This is also supported by SIRI Publish/subscribe and Request/Response

Example: https://api.entur.io/realtime/v1/rest/sx?useOriginalId=true

#### maxSize

-   E.g. _maxSize=10_ (default is 1500)
-   Limits the number of elements in the returned result. _requestorId_ will be used to track changes since last request and is provided in result. An id will be created and returned if not provided.
-   If more data exists, the attribute _MoreData_ will be set to _true_

Example: https://api.entur.io/realtime/v1/rest/et?maxSize=10

#### requestorId

-   E.g. _requestorId=757c9284-0f12-4a46-a557-33a19e80119b_
-   Value needs to be unique for as long as only updated data are needed, a UUID should be used
-   First request creates a short lived session (timeout after e.g. 5 minutes)
-   Subsequent requests returns only changes since last request with the same requestorId

Example: https://api.entur.io/realtime/v1/rest/sx?requestorId=757c9284-0f12-4a46-a557-33a19e80119b

### HTTP GET (GTFS-RT)

HTTP GET https://api.entur.io/realtime/v1/gtfs-rt/trip-updates

HTTP GET https://api.entur.io/realtime/v1/gtfs-rt/vehicle-positions

HTTP GET https://api.entur.io/realtime/v1/gtfs-rt/alerts

**Note:** Fetches complete dataset. Currently only updated every 15 seconds.

#### datasource

-   E.g. _datasource=RUT_. You can find the operator's Codespace-ID in the list above.
-   Limits the results to original dataset-provider

## Additional Resources

For more information on road status, incidents, public transport and schedules, visit [Transportportal.no](https://transportportal.no/en). The portal's data catalogue gives you descriptions and links to data sets and services with information on road status, incidents, public transport, schedules and much more. All data sets are open and available for re-use and as source for your own services.
