How do you get realtime updates for trains arriving at a stop?

115 views
Skip to first unread message

Narayan Iyer

unread,
Apr 5, 2018, 12:04:07 PM4/5/18
to MBTA Developers
Hi,

I am trying to real-time arrival times for trains at a specific stop-id. Which call do I use? I am sure it must be a GTFS-realtime ... right? or does the MBTA v3 API has one of these? I did try:


but it shows for the next day and shows static schedules!

Guidance/Suggestions appreciated. In the meanwhile, I'll continue exploring the wonderful API.

Thanks
-Narayan-

Developer at MBTA

unread,
Apr 5, 2018, 12:10:57 PM4/5/18
to MBTA Developers
Hi Narayan, try the predictions call:

https://api-v3.mbta.com/predictions?filter[stop]=Swampscott

You can also "include" predictions in the schedules call -- see https://api-v3.mbta.com/docs/swagger/index.html#/ for more.

Sincerely,
developer@mbta

Narayan Iyer

unread,
Apr 7, 2018, 11:50:39 AM4/7/18
to MBTA Developers
Hi,

Thanks, and it works like a charm. So, I am also interested in the following details of a stop:

1. Line. Example: if stop id is "Grafton", then it belongs to "Framingham/Worcester" line.
2. Color. If there is a Color associated with the Line. Example: NYC Subway have colors associated with the lines.
3. The last stop. Example; If Grafton is the stop, then inbound train's last stop is South Station, if it is outbound then Worcester.
4. Do you provide the arrival time as Epoch time or Seconds Elapsed since Midnight?

Thanks
-Narayan-

Caleb Sander

unread,
Apr 7, 2018, 4:33:02 PM4/7/18
to massdotd...@googlegroups.com
1. I don't believe there is any query for directly finding what line a stop is part of. For example, https://api-v3.mbta.com/stops/Grafton doesn't show any information about the Framingham line, and you can't use include=routes. I think you must instead construct the mapping by querying for all routes (https://api-v3.mbta.com/routes) and then, for each route, finding the stops on that route (e.g. https://api-v3.mbta.com/stops?filter[route]=CR-Worcester).
2. If you query for routes (e.g. https://api-v3.mbta.com/routes/CR-Worcester), you can extract the color field, which contains a the color of the route in hexadecimal RGB. For example, it is 80276C for Commuter Rail lines.
3. If you query for trips (e.g. https://api-v3.mbta.com/trips?filter[route]=CR-Worcester), you can extract the headsign field, which contains the destination of the train.

You could find the answers to all your questions simply by reading the documentation: https://api-v3.mbta.com/docs/swagger.

—Caleb Sander

--
You received this message because you are subscribed to the Google Groups "MBTA Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to massdotdevelopers+unsubscribe@googlegroups.com.
To post to this group, send email to massdotdevelopers@googlegroups.com.
Visit this group at https://groups.google.com/group/massdotdevelopers.
For more options, visit https://groups.google.com/d/optout.

Developer at MBTA

unread,
Apr 9, 2018, 10:20:18 AM4/9/18
to MBTA Developers
Hi Narayan,

re: question 1, you can get the routes at a particular stop via the /routes/ endpoint: https://api-v3.mbta.com/routes/?filter[stop]=Grafton

Sincerely,
developer@mbta

narayan iyer

unread,
Apr 9, 2018, 5:39:19 PM4/9/18
to massdotd...@googlegroups.com
Thanks! Wlll try your suggestions. 

--
You received this message because you are subscribed to a topic in the Google Groups "MBTA Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/massdotdevelopers/b2jkT1yP17c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to massdotdevelop...@googlegroups.com.
To post to this group, send email to massdotd...@googlegroups.com.

Narayan Iyer

unread,
Apr 9, 2018, 6:29:40 PM4/9/18
to MBTA Developers
... so how do we get service alerts by stop id? I checked the service alert api it seems to provide response in .pb file. Is there a real time service alerts api? 

Thanks
-Narayan-
To unsubscribe from this group and all its topics, send an email to massdotdevelopers+unsubscribe@googlegroups.com.
To post to this group, send email to massdotdevelopers@googlegroups.com.

Narayan Iyer

unread,
Apr 9, 2018, 6:35:35 PM4/9/18
to MBTA Developers
Hi,

So while I was able to get alerts by stop id, how do we get for a Line? 

Alerts by Stop ID:

Alerts by Line?

Thanks
-Narayan-

Developer at MBTA

unread,
Apr 10, 2018, 10:18:02 AM4/10/18
to MBTA Developers
Hi Narayan, filtering by route is supported. If you look at https://api-v3.mbta.com/docs/swagger/index.html#/ under the "alerts" command you can see all the filtering options.

-developer@mbta
Reply all
Reply to author
Forward
0 new messages