Hello, I am writing this guide to showcase what Metro Info use on their Next Bus service. They publish an offical API which can be found here, however I found this API to be to annoying to work with, also the fact that it returns all data in a SQLXML format made it really hard for me to justify working with, so instead here I am publishing my findings of their "private" one.
I only know of 3 endpoints that get all the information I wanted from the service, there may be more, but I will only cover these 3.
The base URL is: http://m.metroinfo.co.nz/" all 3 enpoints are appended to this URL and all requests should be and can only be made by using a POST request. More information on this will be detailed below
This end point is here for their search feature to help you find bus stops along a certain rode or close to a certain road, it returns a JSON object with a list of all stops it found with your search terms.
http://m.metroinfo.co.nz/StreetSearch?terms=<QUERY>
<QUERY> should be the word or words you're wanting to search, I've found most sucsess by just searching with one word query
, but it is upto you.
Remember you'll need to submit this via a POST even though we're not POSTing any data.
Linux Shell:
curl -X POST "http://m.metroinfo.co.nz/StreetSearch?terms=Wainoni" -d ""
PowerShell:
Invoke-WebRequest -UseBasicParsing -Method Post -Uri http://m.metroinfo.co.nz/StreetSearch?terms=Wainoni
This end point is here for a more specific search feature, this uses what I call a public PlatformTag, Metro use a similar name under their documentation, it is usually a 5 or 6 digit
number on every bus stop, examples include: 53116 For Bus Interchange (Platform B) and 14704 for Christchurch Hospital (Tuam), you can usually find it near the bus time tables for that stop next to a QR code or as a metal sign on the bus stop poles. This is used here as a link to Metro's back end PlatformNo.
http://m.metroinfo.co.nz/StreetSearch?terms=<QUERY>
<QUERY> should be the public platform tag, as seen above in the example output there is are JSON properties called PlatformNo and PlatformTag this end point uses PlatformNo which is the public one everyone sees whenever they are at a bus stop around the city.
Remember you'll need to submit this via a POST even though we're not POSTing any data.
Linux Shell:
curl -X POST "http://m.metroinfo.co.nz/PlatformSearch?platform=14704" -d ""
PowerShell:
Invoke-WebRequest -UseBasicParsing -Method Post -Uri http://m.metroinfo.co.nz/PlatformSearch?platform=14704
This is the final endpoint and the most useful in my mind as it returns how far busses are away from the specified PlatformNo note this is the private Metro endpoint one and isn't viewable by the general public without accessing this API, the above two endpoints both return this as part of their data, for example the Bus Interchange (Platform B) stop has a public PlatformTag of 53116, it's PlatformNo is 2 I personally reverse the order in my head so this document doesn't follow the same terminology they use.
http://m.metroinfo.co.nz/RtiData?update=<QUERY>
<QUERY> HAS to be the current UNIX time,
Remember you'll need to submit this via a POST however, unlike the last two endpoints this one requires we post something with our submission, and that is:
platformId which is the private PlatformNo that can only be seen using the above services, so for the Bus Interchange (Platform B) it's private Id or platformId is 2, so we will be posting platformId=2.
Linux Shell:
curl -X POST "http://m.metroinfo.co.nz/RtiData?update=$(date +%s )" -d "platformId=2"
PowerShell:
Invoke-WebRequest -UseBasicParsing -Method Post -Uri http://m.metroinfo.co.nz/RtiData?update=$(([int][double]::Parse((Get-Date -UFormat %s))) -Body @{platformId='536'}).
I hope you found this information helpful in making your apps, the only thing I request is that you keep your polling time similar to that of what their provided interface does, which is every 10 seconds. Other than that I can't see any limitations on what you can and can't do with this.
Thanks, Arefu (Johnathon)