SDK Reference
mta.subway.direction() — resolve a destination to a direction
Reference for mta.subway.direction in mta-js. Resolve a rider-facing destination string into a typed north/south direction, terminal, and display label.
GET
Resolve subway direction from an intermediate destination
TheDocumentation Index
Fetch the complete documentation index at: https://mtaapi.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
mta.subway.direction method resolves a rider-facing destination string (such as "Union Sq") into a typed direction of travel, the terminal the train heads toward, and a ready-to-display label. Use it when a rider tells you where they want to go and you need to translate that into the north / south direction the realtime feed uses — for example, to pre-select the correct direction in an arrivals UI.
This method requires a hosted API key. It resolves destinations against the hosted API’s static GTFS route order and is not available in direct-feed mode.
mta.subway.direction(params)
Parameters
The subway route the rider is traveling on (for example,
'L').The stop ID the rider is departing from (for example,
'L08' for Bedford Av).A rider-facing destination string to resolve against the route’s stop order (for example,
'Union Sq'). Matching tolerates casing and common station-name variations.TypeScript signature
SubwayDirectionResolution object — it does not return null. Branch on resolved: when true, direction, displayDirection, terminal, and destinationStop are populated; when false, reason explains why, and matches may list ambiguous candidates.
Response fields
The resolved route object:
id, plus optional shortName, longName, color, textColor, and type.The destination string exactly as passed in.
The cleaned/normalized form of the destination used for matching.
Whether a direction was successfully determined. When
false, inspect reason and matches.The resolved feed direction:
'north' or 'south'. Present when resolved is true.A human-readable label such as
"toward 8 Av". Present when resolved is true.The name of the terminal station the train heads toward in the resolved direction.
The resolved origin stop object for
fromStopId.The resolved destination stop object that matched
destination.Candidate stops when the destination is ambiguous and could not be narrowed to a single stop.
A short explanation of why resolution failed. Present when
resolved is false.Code example
Example response
NYC Subway realtime feeds use NYCT’s
north / south stop directions, even on east-west lines like the L. mta.subway.direction always resolves to one of those two feed directions, and mta.subway.arrivals accepts the same direction value — along with the rider-facing east / west and uptown / downtown aliases.This method is only available with a hosted
apiKey. It calls the hosted endpoint and resolves against the managed static GTFS snapshot; it is not available in direct-feed mode.Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Query Parameters
Minimum string length:
1Minimum string length:
1Minimum string length:
1Response
200 - application/json
Response for status 200
Previous
BusReference for mta.bus in mta-js. Retrieve live bus vehicle positions, GPS coordinates, heading, next stop, and occupancy for any MTA route.
Next
Resolve subway direction from an intermediate destination