Introducing the V3 API

Paul Swartz
3 min readNov 28, 2017

--

When we last talked, we were launching the newly redesigned MBTA.com. Behind the scenes of the new website, we also rebuilt the API for our data, and we’re ready to share that with everyone. Introducing: the V3 API!

Welcome V3 API!

What’s Better About the V3 API?

If you were a client of the previous API, there are a number of improvements we think you’ll enjoy.

Performance

Since the MBTA is the biggest client of the new API, we wanted to make performance a priority. On a sample of calls, the new API can be up to 300% faster than the V2 API. It’s powered by the same technology, Elixir and Phoenix, that powers other high-performance websites and APIs, including our main website.

Standardized Format

Rather than a custom format, we’ve adopted the JSON API standard. This allows everyone to use the existing ecosystem of implementations to interact with our data, instead of having to write a new client just for the MBTA.

User Feedback

We frequently got requests to include more types of data in the V2 API. Unfortunately, they weren’t easy to add, but we were listening! The V3 API includes a few popular requests:

  • Track numbers and boarding status for the Commuter Rail
  • “X stops away” status from the Green Line signs
  • Prediction and schedule information in one request
  • Improved filtering of responses

Improved Documentation

Our old PDF documentation was very thorough, but PDFs aren’t always the best format for referencing. The V3 API has brand-new documentation built with Swagger and the OpenAPI Specification. Now, you can get detailed information on every endpoint and even try out API calls right from your browser!

Example

It wouldn’t be a good blog post about an API without an example. Luckily, the API doesn’t require a key to try it out, so you can see it from your own browser. We’ll use an example from South Station: https://api-v3.mbta.com/predictions?filter[stop]=South+Station&filter[direction_id]=0&include=schedule

Example of a prediction for a train leaving South Station

There you can see both the new boarding statuses, as well as the included schedule information. Predictions and schedules are connected by the data/attributes/relationships/schedule/id field.

In the V2 API, a client would need to make two different calls to get the schedules and predictions. Even then, it would not have gotten the boarding information that’s now included.

What’s Next?

We have an internal roadmap (including more GTFS data and better alert handling). Plus, we’re planning an update to our GTFS-Realtime data to include more information and be easier to work with. If there are features you’d like to see, we’d love to hear from you! You can reach out to our team in the MassDOT Developers Google Group.

Getting Started

In short, the V3 API is faster, provides more data, and will be a more standardized platform for the future. We hope that will lead to more innovation work in our community.

As of today, the new API is available to everyone. You can sign up for a key at https://api-v3.mbta.com/ to get started.

And, if you want to work on the API or other cool technology projects here at the MBTA, check out the Customer Technology jobs page and get in touch!

--

--