Skip to content

Instantly share code, notes, and snippets.

@grantland
Last active August 1, 2024 14:31
Show Gist options
  • Save grantland/7cf4097dd9cdf0dfed14 to your computer and use it in GitHub Desktop.
Save grantland/7cf4097dd9cdf0dfed14 to your computer and use it in GitHub Desktop.
NextBus API

NextBus API

http://www.nextbus.com/xmlFeedDocs/NextBusXMLFeed.pdf

Agency list

http://webservices.nextbus.com/service/publicXMLFeed?command=agencyList

Obtain a list of available transit agencies.

<?xml version="1.0" encoding="utf-8" ?>
<body copyright="All data copyright agencies listed below and NextBus Inc 2014.">
  <agency tag="actransit" title="AC Transit" regionTitle="California-Northern"/>
  <agency tag="art" title="Asheville Redefines Transit" regionTitle="North Carolina"/>
  <agency tag="sf-muni" title="San Francisco Muni" shortTitle="SF Muni" regionTitle="California-Northern"/>
</body>

Route list

http://webservices.nextbus.com/service/publicXMLFeed?command=routeList&a=<agency_tag>

Obtain a list of routes for a given agency. The agency is specified by the "a" parameter in the query string. The tag for the agency is obtained from the agencyList command.

<?xml version="1.0" encoding="utf-8" ?> 
<body copyright="All data copyright San Francisco Muni 2014.">
    <route tag="F" title="F-Market &amp; Wharves"/>
    <route tag="J" title="J-Church"/>
    <route tag="KT" title="KT-Ingleside/Third Street"/>
</body>

Route config

http://webservices.nextbus.com/service/publicXMLFeed?command=routeConfig&a=<agency_tag>&r=<route tag> 

Obtain a list of routes for a given agency. The route is optionally specified by the "r" parameter. The tag for the route is obtained using the routeList command. If the "r" parameter is not specified, all routes for the agency are returned, limited to 100 routes per request.

<?xml version="1.0" encoding="utf-8" ?>
<body copyright="All data copyright San Francisco Muni 2014.">
  <route tag="F" title="F-Market &amp; Wharves" color="555555" oppositeColor="ffffff" latMin="37.7625199" latMax="37.8085899" lonMin="-122.43487" lonMax="-122.39345">
    <stop tag="5184" title="Jones St &amp; Beach St" lat="37.8072499" lon="-122.41737" stopId="15184"/>
    <stop tag="3092" title="Beach St &amp; Mason St" lat="37.80741" lon="-122.4141199" stopId="13092"/>
    <stop tag="3095" title="Beach St &amp; Stockton St" lat="37.8078399" lon="-122.41081" stopId="13095"/>
    <direction tag="F__OBCTRO" title="Outbound to Castro Station via Downtown" name="Outbound" useForUI="true">
      <stop tag="5184" />
      <stop tag="3092" />
      <stop tag="3095" />
    </direction>
    <direction tag="F__IBCTRO" title="Inbound to Fisherman&apos;s Wharf via Downtown" name="Inbound" useForUI="true">
      <stop tag="3311" />
      <stop tag="5687" />
      <stop tag="5691" />
    </direction>
    <path>
      <point lat="37.76252" lon="-122.43487"/>
      <point lat="37.76267" lon="-122.4352"/>
      <point lat="37.76396" lon="-122.43332"/>
      <point lat="37.76569" lon="-122.43114"/>
      <point lat="37.76726" lon="-122.42915"/>
    </path>
    <path>
      <point lat="37.78036" lon="-122.41261"/>
      <point lat="37.7821" lon="-122.4104"/>
      <point lat="37.78389" lon="-122.40814"/>
      <point lat="37.7856499" lon="-122.40589"/>
    </path>
    <path>
      <point lat="37.7856499" lon="-122.40589"/>
      <point lat="37.7875299" lon="-122.40352"/>
      <point lat="37.78861" lon="-122.40216"/>
      <point lat="37.79094" lon="-122.39919"/>
    </path>
  </route>
</body>

Predictions

http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=<agency_tag>&r=<route tag>&s=<stop tag>

Obtain predictions associated with a particular stop. There are two ways to specify the stop: 1) using a stopId or 2) by specifying the route and stop tags.​

Predictions for multi stops

http://webservices.nextbus.com/service/publicXMLFeed?command=predictionsForMultiStops&a=<agency_tag>&stops=<stop 1>&stops=<stop 2>&stops=<stop 3> 

To obtain predictions associated with multiple stops use the "predictionsForMultiStops" command. The stops are specified by using the "stops" parameter multiple times.

Schedule

http://webservices.nextbus.com/service/publicXMLFeed?command=schedule&a=<agency_tag>&r=<route_tag>

Obtain the schedule information for a route. The route is specified by the "r" parameter. The tag for the route is obtained using the routeList command.

Messages

http://webservices.nextbus.com/service/publicXMLFeed?command=messages&a=<agency tag>&r=<route tag1>&r=<route tagN> 

Obtain messages currently active for a route or a group of routes. Note: this command only returns currently active messages. If a message is configured just to be shown on Tuesdays for example but it is currently Wednesday then the message will not be listed.

Vehicle locations

http://webservices.nextbus.com/service/publicXMLFeed?command=vehicleLocations&a=<agency_tag>&r=<route tag>&t=<epoch time in msec> 

Obtain a list of vehicle locations that have changed since the last time the vehicleLocations command was used. The "t" parameter specifies the last time that was returned by the vehicleLocations command. The time is in msec since the 1970 epoch time. If you specify a time of 0, then data for the last 15 minutes is provided.

@kaijchang
Copy link

I have a problem where not all stops returns are in directions, so I don't know which direction the stop is on.

@nulfex
Copy link

nulfex commented Mar 21, 2019

Does anyone know of a way to use this with https?

@fpurcell
Copy link

Anyone know of any gtfs-realtime feed urls published by Cubic / Next Bus?

@tylershuster
Copy link

@nulfex In our experience the only way is to create a proxy on the server side to parse requests. Our minimal nginx config looks like this:

server {
	server_name nextbus-proxy.your.tld;
	location / {
		proxy_pass http://webservices.nextbus.com/service/publicJSONFeed;
	}
}

Then run certbot on that machine.

@derwaldgeist
Copy link

derwaldgeist commented Nov 13, 2019

Is there any way to access these APIs via HTTPS directly? I want to use them in a mobile app, but mixed content is not allowed there. Proxying via my own server does not make sense to me, because in this case the limitations would apply to the server connection instead to each individual app.

@tylershuster
Copy link

@derwaldgeist, there is no documented way to access these APIs via HTTPS. The server simply refuses SSL connections. You would have to track the mobile app in your proxy. Our client is working with NextBus and they're terminally slow to respond even to requests about documented processes.

@clarsen
Copy link

clarsen commented Jan 6, 2020

Also, the agencies provided by http://webservices.nextbus.com/service/publicXMLFeed?command=agencyList are a lot less versus those available via http://www.nextbus.com/ and the (also HTTP) API it uses.

@vphilot
Copy link

vphilot commented Jan 21, 2020

Been testing it locally and it was working beautifully, but it doesn't work after deployment because of the Mixed Content policy. I'm surprised that a service used by so many agencies refuses HTTPS calls. It's a bummer

@axlevxa
Copy link

axlevxa commented Jul 8, 2021

Hopefully this doesn't jinx it but I have found http://webservices.nextbus.com/ can be replaced above with https://retro.umoiq.com/ for easy HTTPS access. I believe nextbus is somehow trying to rebrand to this new name(?)

Update: it's officially in the docs! Switch away!

@tylershuster
Copy link

Yes, this is recommended based on personal communications with Cubic (parent company of Umo [neé NextBus]) and I have been using it for a while. @grantland recommend updating this gist.

@derwaldgeist
Copy link

Seems as if the APIs are down. I was using

http://webservices.nextbus.com/service/publicJSONFeed?command=predictions&useShortTitles=true

but this shows an error now. Same for the XML endpoint.

Does anyone know an alternative?

@derwaldgeist
Copy link

Update: just saw that the https://retro.umoiq.com endpoint works. Thanks @axlevxa for pointing us to it!

@jragh
Copy link

jragh commented Aug 1, 2022

Trying to use the vehicleLocations command but having no luck, using both https://retro.umoiq.com & https://webservices.umoiq.com endpoint. Actual URL I am using is as follows: https://retro.umoiq.com/service/publicXMLFeed?command=vehicleLocations&a=ttc&t=1659386523. Wondering if anybody is running into the same issue?

Edit: I just want to point out that this request is working for other agencies except the TTC (Toronto Transit Commission). Additionally, other requests such as routeConfig are working with TTC agency.

Edit 2: Seems this was an issue with the TTC agency, as the feed for vehicleLocations have come back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment