Java Connection Error

41 views
Skip to first unread message

Karl Muller

unread,
Jun 16, 2022, 7:45:42 PMJun 16
to mtadeveloperresources
I am using the following code in java to connect to the MTA Numbered Lines API:

try {
            HttpResponse<JsonNode> response = Unirest.get("https://api.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs").header("x-api-key", "<API-KEY>").asJson();

            System.out.println(response.getStatus());
            System.out.println(response.getBody().toString());

}
catch (UnirestException e)
{
            System.out.println("Error in API connection");
}

I am using my api key however it keeps giving me a 403 status and that I am missing the authentication token. Any idea on why this is happening or what I am doing wrong?

Katsute

unread,
Jun 19, 2022, 11:18:53 AMJun 19
to mtadeveloperresources
Make sure that you are using the correct token and that the token is valid. Subway tokens expire after 30 days if not used.

The subway API also does not return a json body, it returns a GTFS feed. Have you considered trying https://github.com/KatsuteDev/OneMTA ?

Karl Muller

unread,
Jun 21, 2022, 10:26:49 PMJun 21
to mtadeveloperresources
Instead of using Unirest, i decided to just use the java.net.url request and it started working so i dont know what the problem was with unirest but thank you for the tip on the GTFS!
Reply all
Reply to author
Forward
0 new messages