Prerequisites
- Install
mta-jswithnpm install mta-js. - Set
MTA_API_KEYin your environment. - Requires
mta-js2.4.0 or later.
1
Find a station code
Call the stations endpoint to look up the RailData station code. For New York Penn Station, use
NY.2
Request station departures
Pass the station code to the departures endpoint. You can optionally filter by a line and limit the number of results.
3
Use the departure data
Each departure includes its station, route, scheduled departure time, and minutes until departure. When RailData provides them, results also include the train ID, destination, track, status, delay, and last-updated time. Pass
includeStops=true to request each train’s stop list.The route is available as a normalized rail line with its name and color:4
Check vehicles, alerts, and route stations
Vehicle positions and alerts can be filtered by line or station. Route stations come from the static GTFS snapshot:
Other rail endpoints
If RailData credentials are not configured on the API server, realtime rail requests return a
503 error. Requests use the same API-key authentication and usage limits as other MTA API endpoints.