Transport for Toronto

Transport for Toronto

Transportation

TTC. We love seeing all the cool and interesting ways people mash up our data. So to help people shorten their development cycles we've created an API. Go. Play. Innovate. Mash up. Make transit better!

Visit API

📚 Documentation & Examples

Everything you need to integrate with Transport for Toronto

🚀 Quick Start Examples

Transport for Toronto Javascript Examplejavascript
// Transport for Toronto API Example
const response = await fetch('https://myttc.ca/developers', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json'
    }
});

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

MyTTC.ca Public API

MyTTC.ca provides a public API for developers to access transit information about Toronto Transit Commission (TTC) services. The API gives developers programmatic access to TTC schedules, arrival times, and real-time vehicle locations. In this post, we'll go over the MyTTC.ca public API documentation, and provide code examples to help you get started.

API Endpoints

MyTTC.ca provides two sets of endpoints:

  1. Static Schedule Data - this data is updated periodically and does not change based on real-time feed. The static data includes routes, stops, and timepoints.
  2. Real-Time Vehicle and Prediction Data - this data is updated in real-time and includes position, speed, and estimated arrival times.

API Documentation

You can find the MyTTC.ca public API documentation at the MyTTC.ca Developers page. The documentation provides instructions for using the API including:

  • Authentication and access instructions
  • Endpoint URL formats
  • Data formats for request and response
  • API examples in various programming languages

For this article, we'll focus on JavaScript examples using Axios library to interact with the API.

Getting Started with JavaScript & Axios

Before we begin, make sure you have Axios installed on your machine or included in your project dependencies. You can add Axios as a dependency in your package.json file:

npm install axios

To get started with API request in JavaScript and Axios, make sure to import the Axios library:

import axios from "axios";

Example API Requests

Here are some examples of API requests using the MyTTC.ca public API:

Get Route and Stop Data

const key = "INSERT_YOUR_API_KEY_HERE";
const endpoint = `https://myttc.ca/api/v1/routes.json?key=${key}&agency=ttc`;
axios.get(endpoint)
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.log(error);
  });

Get Arrival Time Data

const key = "INSERT_YOUR_API_KEY_HERE";
const endpoint = `https://myttc.ca/api/v1/routes/12/stops/22/next.json?key=${key}&agency=ttc&limit=3`;
axios.get(endpoint)
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.log(error);
  });

Get Real-Time Vehicle Location Data

const key = "INSERT_YOUR_API_KEY_HERE";
const endpoint = `https://myttc.ca/locations?type=vehicles&t=uber&key=${key}&agency=ttc`;
axios.get(endpoint)
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.log(error);
  });

Conclusion

The MyTTC.ca public API provides developers with the ability to access transit information about TTC services programmatically. In this post, we went over the MyTTC.ca public API documentation and provided code examples in JavaScript using Axios. By using the API, you can create real-time applications that can improve the transit experience for TTC riders.

📊 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