MBTAPI
A Node.js library for interacting with the Massachusetts Bay Transit Authority's MBTA-Realtime v2 API
Note: This library is neither maintained by nor affiliated with the MBTA
Quick Links: Installation • Usage • Available Methods • Resources • License & Credits
Installation
To use MBTAPI in your project, install it with NPM:
npm install --save mbtapi
Usage
In your Node application code, you can then require the mbtapi
module. Before you can make API requests, you must use the module to create the API client using your own API key:
var mbtapi = ;
Once you have required and created the MBTAPI client, you can make requests against the API using any of the available request methods.
MBTAPI is a Promise-based library, so each method returns a JavaScript Promise object. The results of the API request can be accessed throuh the .then
method:
mbtapi;
This logs out
5 Subway routes
3 Subway routes
12 Commuter Rail routes
189 Bus routes
3 Boat routes
Available API Requests
// Return a complete list of routes for which data can be requested.mbtapi; // Return a list of routes that serve a particular stop, specified by a// stop_id value e.g. "Back Bay" or "70065".mbtapi; // Returns a list of all stops served by a route, specified by a route_id// value such as "Orange" or "88"mbtapi; // Returns a list of all stops near a specified latitude & longitudembtapi; // Returns scheduled arrivals and departures at a particular stopmbtapi; // Returns scheduled arrivals and departures for a particular routembtapi; // Returns scheduled arrivals and departures for a number of routesmbtapi; // Returns scheduled arrivals and departures for a particular tripmbtapi; // Returns arrival/departure predictions, plus vehicle locations and alert// headers, for a stopmbtapi; // Returns arrival/departure predictions, plus vehicle locations and alert// headers, for a routembtapi; // Returns arrival/departure predictions, plus vehicle locations and alert// headers, for a number of routesmbtapi; // Returns arrival/departure predictions, plus vehicle location, for a tripmbtapi; // Returns vehicle locations for a routembtapi; // Returns vehicle locations for a number of routesmbtapi; // Returns vehicle location for a tripmbtapi; // Returns a list of all alerts, with all detailsmbtapi; // Returns a list of all alerts applicable to a route, with all detailsmbtapi; // Returns a list of all alerts for a stop, with all detailsmbtapi; // Returns the full alert object for a given alert IDmbtapi; // Returns a list of all alert headers, with all detailsmbtapi; // Returns a list of all alert headers for a route, with all detailsmbtapi; // Returns a list of all alert headers for a stop, with all detailsmbtapi; // Returns the current server time on the MBTA API servermbtapi;
API Resources
For more information about the MBTA Realtime v2 API, see the MBTA Realtime developer portal
In order to use the API, you need to register for an API key. Also check out the Realtime API v2 documentation, which has in-depth information about each API endpoint's parameters and response.
License & Credits
This library's code © 2015 K. Adam White, released under the MIT License
Use of the MBTA API is subject to the Mass DoT Developers License Agreement
Contributions to the library are welcome: please open an issue if you encounter any problems!