mta.alerts.current(), filter the results for the routes you care about, and display the relevant messages in your application.
1
Call mta.alerts.current()
Pass a Example response:
mode of 'subway' or 'bus' to retrieve alerts for that transit type. You can call both and merge the results if your application covers multiple modes.2
Filter alerts by route or severity
The You can also filter by severity to surface only the most urgent alerts:
alerts array may contain many entries. Filter it down to only the routes your users care about before displaying anything.3
Display alert messages to users
Use
headerText as the alert title and descriptionText for the full detail. Always show both — headerText alone may not give users enough context to act on the disruption.4
Poll for updates
Alerts can be issued or resolved at any time. Poll Sixty seconds is a reasonable interval for alerts. Unlike arrival times, service alerts change less frequently, so you don’t need to poll as aggressively.
mta.alerts.current() on a regular interval to keep your UI up to date.Complete example
Filtering by route
When you need alerts for multiple routes at once, extend the filter to check any route in a set:Alert severity levels indicate how disruptive an event is:
INFO— general notices, such as weekend service changes or planned work during off-peak hoursWARNING— moderate disruptions, such as delays or reduced service frequencySEVERE— significant disruptions, such as suspended service or major reroutes
SEVERE alerts in a banner or push notification, and INFO alerts inline with scheduled service information.