Transport for Washington, US

Transport for Washington, US

Transportation

Washington Metro transport API. Train arrivals, bus predictions, schedules, and more. It's here, and it's all for free. GoBuild(). Metro has officially launched GTFS-RT! Developers now have access to the new Metrorail and Metrobus feeds through the Developer Portal. With the implementation of GTFS-RT, some changes were made to the static GTFS feeds originally hosted on wmata.com. First, the static feeds were split into two modes - rail and bus. Second, the combined feed was retired as of April 15, 2020. This helps keep the most accurate instances of the GTFS and GTFS-RT feeds available to developers. Please log in to the developer portal here to download our new, separated Bus & Rail GTFS files.

Visit API

📚 Documentation & Examples

Everything you need to integrate with Transport for Washington, US

🚀 Quick Start Examples

Transport for Washington, US Javascript Examplejavascript
// Transport for Washington, US API Example
const response = await fetch('https://developer.wmata.com/', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json'
    }
});

const data = await response.json();
console.log(data);

Exploring the WMATA Public API with JavaScript

WMATA provides an easy-to-use API that allows developers to access a large amount of transit data in the DC Metro area. This can be extremely useful for creating applications that help commuters navigate the transit system. In this article, we will explore the WMATA Public API and provide some example code in JavaScript.

Getting Started

First, you will need to sign up for a developer account on the WMATA Developer website (https://developer.wmata.com/). After signing up, you will receive a unique API key that you can use to access the WMATA API.

The WMATA API provides a variety of endpoints that you can use to access transit data. Let's explore a few of the most commonly used endpoints.

Endpoint 1: Station Information

The Station Information endpoint provides information about all Metro stations, including the station name, station code, and location. Here is an example of how to access this endpoint using JavaScript:

const apiKey = 'YOUR_API_KEY';
const url = `https://api.wmata.com/Rail.svc/json/jStationInfo?api_key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => { 
    // Do something with the data 
  })
  .catch(error => console.error(error));

In this example, we are using the Fetch API to make a GET request to the Station Information endpoint. We are passing our API key as a parameter to the endpoint, which is required for authentication. Once we receive the data, we can perform any necessary processing.

Endpoint 2: Train Positions

The Train Positions endpoint provides real-time information about the location and status of all Metro trains. Here is an example of how to access this endpoint using JavaScript:

const apiKey = 'YOUR_API_KEY';
const url = `https://api.wmata.com/TrainPositions/TrainPositions?contentType=json&api_key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => { 
    // Do something with the data 
  })
  .catch(error => console.error(error));

In this example, we are making a GET request to the Train Positions endpoint, passing our API key as a parameter. We are also specifying that we want to receive the data in JSON format. Once we receive the data, we can perform any necessary processing.

Endpoint 3: Next Trains

The Next Trains endpoint provides information about the next trains departing from a given station. Here is an example of how to access this endpoint using JavaScript:

const apiKey = 'YOUR_API_KEY';
const stationCode = 'A01'; // Replace with desired station code
const url = `https://api.wmata.com/StationPrediction.svc/json/GetPrediction/${stationCode}?api_key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => { 
    // Do something with the data 
  })
  .catch(error => console.error(error));

In this example, we are making a GET request to the Next Trains endpoint, passing our API key and the station code as parameters. This will return information about the next trains departing from the station with the specified station code.

Conclusion

In this article, we explored the WMATA Public API and provided some example code in JavaScript. WMATA provides a wealth of transit data that can be extremely useful for creating applications to help commuters navigate the Metro system. With the power of JavaScript and the WMATA API, the possibilities are endless!

📊 30-Day Uptime History

Daily uptime tracking showing online vs offline minutes

Jun 12Jun 14Jun 16Jun 18Jun 20Jun 22Jun 24Jun 26Jun 28Jun 30Jul 2Jul 4Jul 6Jul 8Jul 1104008001440Minutes
Online
Offline

Related APIs in Transportation