Contact Suggest changes

Virtual train

The Virtual train API collects information about the GPS position of the train. It contains a web interface to request trains, and a websocket to receive the position.

Most APIs use train numbers (ritnummer in Dutch), which is more or less the same for each day. It’s not possible to request for another date.

Get train information

You can request information about an individual train, based on a train number. The station code in the url is optional and can be used to request information when the train is at that station. The station code must be in all caps. When leaving the station code out, the default will be where the train currently is. The ?features=zitplaats in the url is optional; this will enrich the data with the number of available seats. The ?features=drukte in the url is optional; this will enrich the data with the crowd forecast. Multiple features can be combined with a comma, e.g. ?features=zitplaats,drukte
Parameter Description
ritnummer Number of the train
station Current station
vervoerder Train operator, e.g. NS
materieeldelen Train coaches
materieelnummer Number of the train coach
type Type of train coach
faciliteiten Facilities in this train available, i.e. TOILET, STROOM (power), WIFI, STILTE (silence zone), TOEGANKELIJK (wheelchair accessible), FIETS (bike parking), BISTRO (restaurant)
afbeelding Image of this type of train
zitplaatsen Optional information about the available seats in this coach. These are: staanplaatsEersteKlas (standing space first class), staanplaatsTweedeKlas (standing space second class), zitplaatsEersteKlas (seats first class), zitplaatsTweedeKlas (seats second class), klapstoelEersteKlas (tip-up chairs first class), klapstoelTweedeKlas (tip-up chairs second class).
ingekort Whether this train is shorter than usual
length Number of coaches

Get all trains

This request will give you all the information about all trains. The response shows all the stops the train will make. The response is over 10MB, so please use this resource with caution.

Location information

You can request train positions from https://ns-api.nl/virtualtrain/api/v1/locatie/treinen.

The GPS location of trains also has a websocket. If you'd like to have access to this websocket, please contact us.

Request ritnummer based on materieelnummer

If you don’t have a train number, you can look it up based on a materieelnummer (coach number). This materieelnummer is displayed in all trains above the doors.

The response code will be 204 when there is no train number for that coach number. The response code will be 200 and includes the train number as integer in the response.

Prognoses of crowded train

It’s possible to request the expected number of people on the train, as well as the capacity of the train.

Shorter train (ingekort)

It’s possible to request the list with trains that are shorter than usual. This is only the case when the train reaches capacity.

Examples

https://ns-api.nl/virtualtrain/api/v1/trein/3031

https://ns-api.nl/virtualtrain/api/v1/trein/3031?features=zitplaats

https://ns-api.nl/virtualtrain/api/v1/ingekort

https://ns-api.nl/virtualtrain/api/v1/prognose/3031

https://ns-api.nl/virtualtrain/api/v1/ritnummer/8659