Connect to the NS (Dutch Railways) API

Access the NS api and download current departure times, disruptions and engineering work, the station list, and travel recommendations from station to station. All results will be returned as a 'data.frame'. NS (Nederlandse Spoorwegen; Dutch Railways) is the largest train travel provider in the Netherlands. for more information about the API itself see <>. To use the API, and this package, you will need to obtain a username and password. More information about authentication and the use of the functions are described in the vignette.

CRAN_latest_release_date license Project Status: Active – The project has reached a stable, usablestate and is being activelydeveloped. thanks-md lifecycle Travis-CI BuildStatus codecov

The Dutch National Railway service (NS; Nederlandse Spoorwegen) has an API where we can query for travel advise, see the current trains on a given station, see if there is any delays or work on the tracks and NS also provides a list with geolocation of all the stations.

The goal of nsapi is to make it easy to gather data from the NS API. The package returns data frames for every response.

an incredibly ugly logo for this package, we need ahexsticker!


You can NOT YET install the released version of nsapi from CRAN with:


But you can install the development version from GitHub with:

# install.packages("devtools")


This is a basic example which shows you how you get travel information:

treinplanner <- get_travel_advise(
  fromStation = "Leiden Centraal", 
  toStation = "Utrecht Centraal",
  departure = TRUE,
  yearCard = TRUE,
  previousAdvises = 1, 
  nextAdvises = 1)
#>   Melding AantalOverstappen GeplandeReisTijd ActueleReisTijd
#> 1      NA                 1             0:55            0:58
#> 2      NA                 0             0:42            0:42
#> 3      NA                 1             1:00            1:00
#> 4      NA                 0             0:42            0:42
#>   VertrekVertraging AankomstVertraging Optimaal GeplandeVertrekTijd
#> 1              <NA>             +3 min    FALSE 2018-08-10 21:05:00
#> 2              <NA>               <NA>     TRUE 2018-08-10 21:22:00
#> 3              <NA>               <NA>    FALSE 2018-08-10 21:30:00
#> 4              <NA>               <NA>    FALSE 2018-08-10 21:52:00
#>    ActueleVertrekTijd GeplandeAankomstTijd ActueleAankomstTijd
#> 1 2018-08-10 21:05:00  2018-08-10 22:00:00 2018-08-10 22:03:00
#> 2 2018-08-10 21:22:00  2018-08-10 22:04:00 2018-08-10 22:04:00
#> 3 2018-08-10 21:30:00  2018-08-10 22:30:00 2018-08-10 22:30:00
#> 4 2018-08-10 21:52:00  2018-08-10 22:34:00 2018-08-10 22:34:00
#>         Status     ReisDeel
#> 1    VERTRAAGD c("NS", ....
#> 2 VOLGENS-PLAN NS, Inte....
#> 3 VOLGENS-PLAN c("NS", ....
#> 4 VOLGENS-PLAN NS, Inte....


  1. What Can I do with the package?
  • You can access the departures from a station, disruptions (planned and unplanned), get travel advise (between stations) and a list of all stations (in the Netherlands and some outside.). In the vignette I’ve described how to use the functions.
  1. I’m getting a curl timeout!
  • Yes… That happens, sometimes. The NS website does not always return errors but just times you out once in a while. Take a deep breath, retry.
  1. Error Bad request or HTTP 400
  • Your username and password might not be set properly
  1. How do I set a password and username?
  • See Authentication in the vignette


The package is MIT licensed although the information from NS is probably proprietary

codecoverage <- covr::package_coverage(path = ".",type = "tests")
#> nsapi Coverage: 18.87%
#> R/api_calls_authentification.R: 4.84%
#> R/utils.R: 24.67%


nsapi 0.1.0

  • renamed all functions to start with get_*
  • Time is now safely parsed as "Europe/Amsterdam" timezone


  • basic version ready
  • contains api call, secrets
  • all endpoints covered
  • pkgdown complete
  • vignette with basic functions covered
  • sick logo added
  • low package coverage

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.1.1 by Roel M. Hogervorst, 3 years ago ,

Report a bug at

Browse source code at

Authors: Roel M. Hogervorst [cre, aut]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports crul, xml2

Suggests testthat, knitr, rmarkdown, covr

See at CRAN