Home Page Full Legacy API Documentation
Using the API is a simple two-step process, or three-step if you wish to query railcard-discounted fares. It involves making HTTP requests to a specified URL, and parsing the response received in JavaScript Object Notation (JSON). API clients must support receiving results in compressed format, and should set the Accept-Encoding HTTP header to indicate which compression format they prefer. The API server supports deflate and gzip compression. The server will include a response header of
Access-Control-Allow-Origin: *to support Cross-Origin Resource Sharing and allow the API to be called from JavaScript running in another website.
Send a HTTP request to
https://gw.brfares.com/legacy_ac_loc?term=XXXXXXwhere XXXXXX is the first few letters from the location of interest. E.g. a request to
https://gw.brfares.com/legacy_ac_loc?term=ldsreturns the following JSON
[ {"label":"(LDS) LEEDS.","value":"LEEDS.","code":"LDS"} ]and
https://gw.brfares.com/legacy_ac_loc?term=oxfreturns
[ {"label":"(OXF) OXFORD","value":"OXFORD","code":"OXF"}, {"label":"OXFORD CIRC UND","value":"OXFORD CIRC UND","code":"ZOC"}, {"label":"OXFORD+BUS","value":"OXFORD+BUS","code":"J931"} ]Make a note of the code parameter for the location you are interested in.
https://gw.brfares.com/legacy_querysimple?orig=LDS&dest=OXFwhich returns
{ "orig": {"nlc":"8487","crs":"LDS","name":"LEEDS.","code":"LDS"}, "dest": {"nlc":"3115","crs":"OXF","name":"OXFORD.","code":"OXF"}, "travelcard_orig": false, "travelcard_dest": false, "zonal_orig": false, "zonal_dest": false, "railcard": {"code":" ","name":"PUBLIC"}, "railcard_valid": true, "fares": [ { "category": {"code":0,"desc":"WALKUP"}, "flow_orig": {"nlc":"Q083","crs":"","name":"","code":"Q083"}, "flow_dest": {"nlc":"Q475","crs":"","name":"","code":"Q475"}, "group_orig": {}, "group_dest": {}, "travelcard_orig": false, "travelcard_dest": false, "zonal_orig": false, "zonal_dest": false, "fare_setter": {"code":"IXC","name":"CROSSCOUNTRY"}, "route": {"code":700,"name":"NOT VIA LONDON"}, "london_code": {"code":0,"desc":"NO"}, "ticket": {"code":"7DF","name":"SEVEN DAY 1ST","type": {"code":2,"desc":"SEASON"}, "tclass": {"code":0,"desc":"1ST"}}, "restriction_code": " ", "railcard_restrictions": [], "reversible": true, "adult": {"status": {"code":"000","name":"ADULT","id":0}, "fare": 64000}, "child": {"status": {"code":"001","name":"CHILD","id":1}, "fare": 32000} }, { "category": {"code":0,"desc":"WALKUP"}, "flow_orig": {"nlc":"R629","crs":"","name":"","code":"R629"}, "flow_dest": {"nlc":"R675","crs":"","name":"","code":"R675"}, "group_orig": {}, "group_dest": {}, "travelcard_orig": false, "travelcard_dest": false, "zonal_orig": false, "zonal_dest": false, "fare_setter": {"code":"IEC","name":"EAST COAST"}, "route": {"code":0,"name":"ANY PERMITTED"}, "london_code": {"code":1,"desc":"YES"}, "ticket": {"code":"FOR","name":"ANYTIME 1R","type": {"code":1,"desc":"RETURN"}, "tclass": {"code":0,"desc":"1ST"}}, "restriction_code": " ", "railcard_restrictions": [], "reversible": true, "adult": {"status": {"code":"000","name":"ADULT","id":0}, "fare": 41200}, "child": {"status": {"code":"001","name":"CHILD","id":1}, "fare": 20600} },and so on (with a lot more where that came from!).
If you want to use a railcard then you can look up the database ID for the railcard by sending a request to
https://gw.brfares.com/legacy_ac_rlc?term=16-25which will return something like
[ {"label":"16-25 RAILCARD","value":"YNG 16-25 RAILCARD","code":"YNG"} ]The unique railcard code can then be added to the fares query URL as follows:
https://gw.brfares.com/legacy_querysimple?orig=LDS&dest=OXF&rlc=YNG
Note: This is not a full description of all the data returned in a query, and consists merely of a few hints and general pointers.
All locations have a National Location Code (NLC). This 4-character alphanumeric code uniquely identifies the location within the fares database. Fares locations that are also actual railway stations have in addition a Computer Reservation System (CRS) code. These 3-character alphabetic codes are widely used, although not ideal for uniquely identifying fares locations—since fares exist to lots of places that aren't railway stations (and thus don't have a CRS code), and there are even some duplicate CRS codes (e.g. as of July 2013, ZCW can refer either to Canada Water, or to Canary Wharf DLR station). However NLC codes aren't much used beyond the fares database and ticket encoding, so CRS codes are useful for interfacing with other systems.
Railcards also all have a code in the fares data, e.g. YNG = 16-25 Railcard, NEW = Network Railcard, NGC = Network Gold Card etc. These are fairly consistent and non-changing. Note however that they are different to the discount codes actually printed on tickets.
The bulk of the JSON data comprising a query result consists of an array of fares available between the origin and destination locations. The relevant and/or interesting parameters associated with each fare are as follows: