developer.theNextTrain.com

An overview of technical resources available to developers on http://thenexttrain.com

API Documentation

This site offers an API that can be queried by station or by pair of stations to return up to the next 5 departures at that station, or between those stations. There is also a API to request information about all stations at an agency, and one to get information about all available agencies.

General Information

Each url serves a dual purpose. It serves html results to browsers, and serves up JSON feeds to developers. To TEST the JSON feed, each url can have a parameter added to the end of the url to force the output type to JSON ?output=json . This must not be used for anything beyond testing. As part of the requirements to use this feed, http requests must set the HTTP_ACCEPT header to application/json (which will trigger the JSON output format), and must also set a valid HTTP_USER_AGENT which has the name of the application requesting data, and the url.

A valid request would be

GET /web HTTP/1.1
User-Agent: theNextTrain http://thenexttrain.com/
Accept: application/json
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

For details on how to set the proper header values consult your programming language reference.

Agency List

example output:

{
    "agencies":[
        {
            "name":"Long Island Railroad",
            "slug":"lirr",
            "url":"http://mta.info/lirr/"
        }
    ]
}

Station List

Example Output:

{
    "agency":{
        "slug":"lirr",
        "url":"http://mta.info/lirr/",
        "name":"Long Island Railroad"
    },
    "stops":[
    {
        "url":"http://www.mta.nyc.ny.us/lirr/html/ttn/mineola.htm", 
        "slug":"mineola",
        "name":"Mineola"
    },

    {
        "url":"http://www.mta.nyc.ny.us/lirr/html/ttn/montauk.htm", 
        "slug":"montauk",
        "name":"Montauk"
    },
    {
        "url":"http://www.mta.nyc.ny.us/lirr/html/ttn/newhydep.htm", 
        "slug":"new-hyde-park",
        "name":"New Hyde Park"
    },
    {
        "url":"http://www.mta.nyc.ny.us/lirr/html/ttn/pennstat.htm", 
        "slug":"penn-station",
        "name":"Penn Station"
    }
    ]
}

Station Departures

Example Output:

{
    "request":"http://thenexttrain.com/at/lirr/new-hyde-park/",
    "agency":{
        "slug":"lirr",
        "url":"http://mta.info/lirr/",
        "name":"Long Island Railroad"
    },
    "stop":{
        "name":"New Hyde Park",
        "url","http://www.mta.nyc.ny.us/lirr/html/ttn/newhydep.htm", 
        "slug":"new-hyde-park"
    },
    "starting":"11:35pm",
    "ending":"5:45am",
    "departures":[
        {   
            "time":"11:39pm",
            "headsign":"OFF-PEAK Eastbound to Port Jefferson ",
            "route":"Port Jefferson"
        },
        {   
            "time":"12:13am",
            "headsign":"OFF-PEAK Eastbound to Port Jefferson ",
            "route":"Port Jefferson"
        },
        {   
            "time":"12:58am",
            "headsign":"OFF-PEAK Westbound to New York",
            "route":"Port Jefferson"
        },
        {   
            "time":"3:38am",
            "headsign":"OFF-PEAK Eastbound to Port Jefferson ",
            "route":"Port Jefferson"
        },
        {   
            "time":"4:11am",
            "headsign":"OFF-PEAK Westbound to New York",
            "route":"Port Jefferson"
        }

    ]
}

Trip Departures

Example Output:

{
    "request":"http://thenexttrain.com/at/lirr/penn-station/to/new-hyde-park/",
    "agency":{
        "slug":"lirr",
        "url":"http://mta.info/lirr/",
        "name":"Long Island Railroad"
    },
    "from":[
        {
            "name":"New Hyde Park",
            "url","http://www.mta.nyc.ny.us/lirr/html/ttn/newhydep.htm", 
            "slug":"new-hyde-park"
        }

    ],
    "to":[
        {
            "name":"Penn Station",
            "url","http://www.mta.nyc.ny.us/lirr/html/ttn/pennstat.htm", 
            "slug":"penn-station"
        }

    ],
    "starting":"11:40pm",
    "ending":"6:00am",
    "departures":[
        {   
            "time":"12:58am",
            "headsign":"OFF-PEAK Westbound to New York",
            "route":"Port Jefferson"
        },
        {   
            "time":"4:11am",
            "headsign":"OFF-PEAK Westbound to New York",
            "route":"Port Jefferson"
        },
        {   
            "time":"4:59am",
            "headsign":"OFF-PEAK Westbound to New York",
            "route":"Port Jefferson"
        }

    ]
}

Notice a problem? Have an idea? Drop us a Line