api.irail.be
Note: As of October 2017, we update our documentation. Please see https://docs.irail.be for the new API documentation. Please see https://status.irail.be for the current service status. For more information, read this.
Welcome to the iRail API! Before you start implementing this API, a lot of code has been written already! Feel free to look around on our Github page for more information on wrappers for your programming language of choice.
1. Query for station / download all stations
Request
https://irail.be/stations/NMBS?q={query}
Alternatively, you can check out our repo at https://github.com/iRail/stations for a CSV of all stations, and nodejs scripts to convert this CSV to other formats.
Another alternative is the deprecated https://api.irail.be/stations/ resource which takes no arguments at all.
Arguments
optional (leave empty for all stations):
?q=Brussel
Response
E.g., for Brussels: curl https://irail.be/stations/NMBS?q=Brussels { "@graph": [ { "@id": "http://irail.be/stations/NMBS/008811304", "alternative": [ { "@language": "en", "@value": "Brussels-Luxemburg/Brussels-Luxembourg" }, { "@language": "fr", "@value": "Bruxelles-Luxembourg" }, { "@language": "nl", "@value": "Brussel-Luxemburg" } ], "name": "Brussel-Luxemburg/Bruxelles-Luxembourg", "latitude": "50.838943", "longitude": "4.373674" }, ... ] }
2. Querying for a route from one station to another
Request
https://api.irail.be/connections/?to={station1}&from={station2} (OPTIONAL:) &date={dmy}&time=2359&timeSel=arrive or depart
date
dmy (day of month with leading 0, number of the month with leading 0, 10 or 11 (for 2010 or 2011)) e.g., 010115 is the first of January 2015
time
Hours in 24 hour format concatenated with minutes with leading 0!
timeSel
Whether the date & time are for arrival or depart. Should be “arrive” or “depart”
Response
(with random data)
<connections> <connection id="0"> <departure delay="xx"> <!--xx in seconds--> <station locationX="4.038586" locationY="50.943053">AALST</station> <time formatted="Y-m-d\TH:i:s\Z"> <!-- time in iso 8601 --> U <!--(= unixtime)--> </time> <vehicle>BE.NMBS.P2000</vehicle> <platform normal="yes">3</platform> </departure> <vias number="1"> <via id="0"> <arrival> <time formatted="Y-m-d\TH:i:s\Z"> U<!--(= unixtime)--> </time> <platform>5</platform> </arrival> <depart> <time formatted="iso8601"> U <!--(= unixtime)--> </time> <platform>6</platform> </depart> <timeBetween>xx</timeBetween> <station locationX="..." locationY="..." URI="...">Gent Sint Pieters</station> <vehicle>BE.NMBS.P2000</vehicle> </via> </vias> <arrival delay="xx"> <!--delay on arrival in seconds --> <station location="... ..." URI="..."> Harelbeke </station> <time formatted="Y-m-d\TH:i\Z"> U <!--(= unixtime)--> </time> <vehicle>BE.NMBS.P2000</vehicle> <platform normal="true">1</platform> </arrival> <duration delay="yes">seconds</duration> </connection> ... </connections>
3. Departures and Arrivals in a certain station
Request
https://api.irail.be/liveboard/?station=STATIONNAME&fast=true
or
https://api.irail.be/liveboard/?id=BE.NMBS.008892007
fast
The direction of a train in the liveboard overview is not a station, but a general direction. The flag fast=true
will omit trying to link a direction to a station. We recommend for the liveboard overview to always put fast=true
.
station
Name of the station
id
id returned by a previous request
date
date of depart/arrival – dmy
time
time of depart/arrival –
arrdep
DEP or ARR for arrival or departure
Response
<liveboard version="1.0" timestamp="123456789"> <station locationX="4.21485" locationY="...">Ghent Sint Pieters</station> <departures number="2"> <departure delay="xx" id="0"> <station locationX="..." locationY="...">STATIONNAME</station> <vehicle>Be.NMBS.P2000</vehicle> <time formatted="iso8601">U</time> <platform>X</platform> </departure> <departure delay="xx" id="1"> <station locationX="..." locationY="...">STATIONNAME</station> <vehicle>BE.NMBS.P2001</vehicle> <time formatted="iso8601">U</time> <platform>X</platform> </departure> </departures> </liveboard>
4. Vehicle
Request
https://api.irail.be/vehicle/?id=BE.NMBS.P1234
id
specify the vehicle id. This should be according the iRail specification
Response
<vehicleinformation version="1.1" timestamp="1469090808"> <vehicle locationX="6.03711" locationY="50.635157">BE.NMBS.IC545</vehicle> <stops> <stop> <station id="BE.NMBS.008844628" locationX="6.03711" locationY="50.635157" URI="http://irail.be/stations/NMBS/008844628" standardname="Eupen">Eupen</station> <platform normal="1">2</platform> <departureDelay>0</departureDelay> <departureCanceled>0</departureCanceled> <scheduledDepartureTime formatted="2016-07-21T22:22:00">1469132520</scheduledDepartureTime> <scheduledArrivalTime formatted="2016-07-21T22:22:00">1469132520</scheduledArrivalTime> <arrivalDelay>0</arrivalDelay> <arrivalCanceled>0</arrivalCanceled> </stop> ... </stops> </vehicleinformation>
Error Response
When incorrect requests has been made or when an error occurs, we will provide an error message like this:
<error version="1.0" timestamp="1289951590" code="1"> You should ... </error>
at this moment code = 1 is a user error. code = 2 is a server error.
Arguments on all functions
lang
if you add &lang= NL, EN, DE or FR to a function, the given station will be interpreted in that language, and the stationnames will be outputted in that language.
format
Currently we support 2 formats: xml and json
- &format=xml will output the above examples
- &format=json will output the xml-converted json
- &format=jsonp&callback=foo will package the json string into a callback function.
Alerts
setting alerts=true will enable alert messages in the response
Thanks for your efforts to implement this.
The API https://irail.be/stations/NMBS does not seem to react to no parameters at all. Basically I’m looking for a list of all stations with Latitude and Longitude information.
Hi Vincent,
Check https://github.com/iRail/stations for the raw data in CSV format. If you want the JSON file from the URL you’ve mentioned, you need to configure an Accept header with your request. E.g., “Accept: application/json” will return JSON. We have seen that this is not too straightforward and will soon add a GET parameter to retrieve JSON right away.
Pieter
Great innitiative :). Is there any way to check vehicle delay from a date in the past ?
http://api.irail.be/vehicle/?id=BE.NMBS.P1234&fast=true&date= xxx ?
Not at this time, but we’re working on a solution
You are saying you are working on it. Could you please tell me if this data is available now in 2017?
Thank you
Yes it is – e.g., https://api.irail.be/vehicle/?id=BE.NMBS.P8008&date=120517
It seems that searching in the past is limited to a few days. Example, for today the limit is 140217. A day earlier, 130217, does not give results anymore. Why?
The vehicle location seems to be set to the coordinates of the departure station whilst I would have expected to get its real position. Is that information available somewhere?
With railtime, it was possible to see when a vehicle was arrived in (or had left) a specific station and this was really useful information. No App (SNCN / Railer) is showing this information.
Thanks in advance for your answer.
I have noticed the same. The delays however seem to be updated, but the vehicle position stays at its initial position.
Indeed… We’re looking into this: https://github.com/iRail/iRail/issues/92
Vraagje, bij de request: http://api.irail.be/connections/?to={station1}&from={station2} Waarom station1 en station2 als gewone strings ipv ID van station? Wat als de stations van naam veranderen? Hoe gebeurt de encoding van deze strings?
Dag Bart,
ID’s werken ook. Historische redenen… API is ondertussen 5 jaar oud 🙂
Why does “querying for a route from one station to another” use the dmy format and “fepartures and Arrivals in a certain station” the mdy format? BTW, love the api!
Hi Glenn,
I believe this was a typo. This has been correct, thanks!
Pieter
Can we get station name from latitude and longitude ?
Pingback: Stations ophalen wordt ook static dan maar… | De toekomst van digitale signalisatie
Peter can you help ?
We are looking for a system that show us the departures of all busses at uz jette, in a nice formatted way, as well from de lijn but also from the nivb.
Because i’m not a prorammer, i’m not good at this.
So could you write a php page that does this ?
Thanx
I want to ask how i can make a page with the leaving times of bussess at jette hostpital.
For mivb and de lijn.
Can you help
Hi,
Some trains have one floor (quite old in general) and some two floors (comfortable, less crowded).
Is it possible to identify from the API response the number of floors? Is this information encoded in the vehicle name (e.g. BE.NMBS.IC739) somehow?
Thanks,
Ignat.
Hi Ignat, we are working on this during during open Summer of code (http://summerofcode.be) this year during the project Spitsgids. We will post updates during July!
Een vraagje: ik probeer de real-time gtfs data van trip_updates.pb in te lezen in OpenTripPlanner, maar OpenTripPlanner crasht op het feit dat er geen trip_id ‘s in de data zitten. Dit is een dump van trip_updates.pb:
trip {
trip_id: “”
start_date: “20160708”
schedule_relationship: SCHEDULED
route_id: “IC2009”
}
stop_time_update {
stop_sequence: 0
arrival {
delay: 120
time: 1467964440
}
stop_id: “8872009:1”
}
stop_time_update {
stop_sequence: 1
arrival {
delay: 60
time: 1467964860
}
stop_id: “8871100:3”
}
Het trip_id is dus inderdaad een lege string. Is dit de bedoeling? Indien ja, hoe kan men dan achterhalen over welke trip het precies gaat?
Alvast bedankt!
Dit is inderdaad een gekende bug. Meer daarover lees je hier: https://github.com/iRail/brail2gtfs-rt/issues/20
We hopen deze zo snel mogelijk op te lossen door onze GTFS bestanden regelmatiger up te daten. De lege trip_id komt omdat deze trein nog niet werd gevonden.
Pingback: Small enhancements of the API documentation | iRail
Hi, I I’ve just discovered your project and there is (at least) one thing I don’t understand : from where does the datas come from ? I suppose that sncb don’t furnish an api. So … ? Thanks.
Hi Joos, the data is scraped from the SNCB’s website. You can see how we do it at https://github.com/iRail/iRail. The SNCB knows about our project and we are looking into ways to make sharing data a more flawless experience.
Nice project. Is it possible to get a list of all train id’s? Does the train id identify the trip (e.g. mechelen to leuven departure at 8:15) or the physical train (can be used for multiple trips)?
Thanks Jos! You can get a list of all train IDs in our data dump in the routes.txt: http://gtfs.irail.be/nmbs/nmbs-latest.zip
In our specific implementation, these route identifiers occur once a day, so a route identifier (e.g., P8008) at a certain date (e.g., today) identifies a physical train that drives. However, it may be possible that this train splits, or the same physical train is then used for a different route identifier (e.g., an IC train that terminates in Ghent and continues as a L (local) train to somewhere in West-Flanders).
Hello,
First thanks for providing this API.
I would like to use it in a little test project.
The API would be called from the browser via an AJAX call.
Unfortunately this does not work up to now.
I suspect the cause being same-origin policy: the javascript is provided by my site and the api by irail.be.
I do not think cors is enabled on your API.
Is it done on purpose? Would it be possible to activate it?
Thanks.
Thanks Eric for your comment. Can you be more specific about what you’re trying to do? CORS are enabled on api.irail.be. Can you maybe share some example code?
Hello Pieter, Thanks for your quick reply.
I made a basic test page on:
https://api.jackjack.be/testirail.html
In my case Firefox is well calling the API but is refusing to render the result.I think because the Access-Control-Allow-Origin header is not returned by the API.
There are some firefox plugins that are adding this header. When using them the above test page is working.
Do you think I make a mistake somewhere?
Hi Eric, nice catch indeed! The https://irail.be/stations/NMBS/ has no access control enabled at this time, so you are right! I will add this to the application in the near future!
In meantime, feel free to still use https://api.irail.be/stations.php?format.json instead. You will have to do the filtering in javascript though. Will that work in meantime?
Indeed, on this URL the header is present. I will use it in the meantime. Just have to find out the right regular expression 😉
Pingback: API’s gevonden – Digitale signalisatie voor openbaar vervoer
Is het mogelijk gebruikerservaring in jullie databank te plaatsen met een zelfgeschreven app? (erg druk, druk, niet druk)
Is het mogelijk de drukte te bekijken van voorgaande dagen?
Kan het zijn dat er een conversie foutje zit bij het Json formaat?
Er zit namelijk nog een @ bij id
{
“id”: “BE.NMBS.007015400”,
“locationX”: “-0.1260606”,
“locationY”: “51.5310399”,
“@id”: “http://irail.be/stations/NMBS/007015400”,
“standardname”: “London Saint Pancras International”,
“name”: “London Saint Pancras International”
},
En klopt het wel dat er 2x id gebruikt wordt? dit geeft namelijk circular structure fouten..
Dag Kevin,
Geen conversie-fout: onze nieuwe identificatoren voor stations maken gebruiken van HTTP-URI’s (werken overal) ipv lokale identificatoren (werken enkel in context van iRail). Voor backward compatibility houden we de `id` er in. Voor compatibility met de JSON-LD specificatie gebruiken we @id.
Yesterday and today I got a lot of “Error 503 service unavailable” for the services; also this website and irail.be had the same error. Is the issue identified?
Hi Adrian,
Yes, our servers were experiencing some hick-ups. Sorry for the inconvenience!
Pingback: iRail server move and bugfixing – iRail
Hi, the value that is given at delay, is that in minutes? seconds?
In stations op het vertrekscherm zijn er indicators “aan perron” te vinden. Dus niet of een trein die van A naar B rijdt station A heeft verlaten ( ‘left’ in de XML-bestanden ) , maar effectief of de trein aan het perron van station B is. Is deze info ook ergens op te vragen? Op de NMBS-website zelf alleszins nergens…
Deze data is helaas niet online beschikbaar. Wij kunnen enkel data weergeven die ofwel op de website, ofwel in de app beschikbaar is. We hebben nog geen bronnen gevonden waaruit we kunnen afleiden welke treinen de status “Komt aan” of “Aan perron” heeft. Indien je graag toegang wilt tot deze data, zul je je tot de NMBS moeten wenden met de vraag deze openbaar te maken.
Groeten,
Bert
Thank you for a nice api. I already tried with nmbs and it works as it supposed to.
But, it doesnt work the same with delijn.
Any help or suggestions how to retrieve delijn data ?
It seems delays are not registered?
https://api.irail.be/vehicle/?id=BE.NMBS.3631&date=190819 this was for example a delayed train (in brussels south anyway it arrived 20 minutes late), but this does not seems to be reflected in the resulting data.
hi,
nice API. Is there any information about railwaycrossings?
to check if the beams are closed or not?
Hello, while using the API for a React map exercise, I noticed an issue with the data for station “Goebelsmühle”.
It seems the latitude and longitude are swapped, as the marker is showing in Somalia 🙂
The station id is BE.NMBS.008200129