Authentication overview

Transport for Vancouver, Canada, through its TransLink Developer Program, provides programmatic access to public transit data using an API key-based authentication model. This method requires developers to obtain a unique alphanumeric string (API key) that identifies their application when making requests to the TransLink API endpoints. The API key serves as the primary credential for accessing data such as real-time vehicle positions, estimated times of arrival, and static schedule information.

The TransLink API key system is designed to be straightforward for developers, facilitating quick integration of transit data into applications for route planning, real-time tracking, and academic research. By requiring an API key with each request, TransLink ensures that API usage can be monitored and managed, helping to maintain service quality and prevent abuse. This approach is common in public-facing APIs where the primary goal is to provide data access with minimal setup overhead for developers, while still offering a layer of access control.

Supported authentication methods

The TransLink API primarily supports API key authentication. This method is suitable for client-side applications or server-side integrations where the key can be securely stored and transmitted. The API key is passed as a query parameter in each API request.

Method When to Use Security Level
API Key
  • Accessing public transit data for read-only operations.
  • Applications where user-specific data is not involved.
  • Server-to-server communication where the key can be securely managed.
  • Client-side applications where keys are restricted to public, non-sensitive data.
Moderate (depends heavily on key management and environment)

While API keys offer simplicity, it is important to understand their security implications. Unlike token-based authentication methods like OAuth 2.0, API keys alone do not typically provide mechanisms for user consent or granular permissions for individual users. They usually grant access on behalf of the application itself. For more complex scenarios requiring user authentication or fine-grained access control, developers might need to implement additional authentication layers within their applications, or refer to more advanced authentication standards like OAuth 2.0 specifications if such capabilities become available through future API enhancements.

Getting your credentials

To obtain an API key for the TransLink API, developers must register an account on the official TransLink Developer Portal. The registration process typically involves providing basic contact information and agreeing to the terms of service. Once registered, a unique API key is usually generated and made available through a personal dashboard or developer console.

  1. Visit the TransLink Developer Portal: Navigate to the developer.translink.ca website.
  2. Register for an Account: Locate the registration link and provide the requested details, which may include your name, email address, and organization (if applicable). You will likely need to confirm your email address.
  3. Log In: After successful registration and email verification, log in to your newly created developer account.
  4. Generate API Key: Within your developer dashboard, there should be an option to generate or view your API key. The portal is designed to provide clear instructions on where to find and manage your credentials.
  5. Store Your Key Securely: Once obtained, treat your API key as a sensitive credential. Do not embed it directly into publicly accessible client-side codebases or commit it to version control systems without proper obfuscation or environment variable management. Secure storage is critical for preventing unauthorized access to the TransLink API.

For more detailed step-by-step instructions and any specific requirements, always refer to the official TransLink API documentation found on their developer portal. This documentation provides the most current information regarding credential acquisition and usage.

Authenticated request example

Once you have obtained your API key from the TransLink Developer Portal, you can use it to make authenticated requests. The TransLink API typically expects the API key to be passed as a query parameter named apiKey in the request URL. Below is an example using cURL, a common command-line tool for making HTTP requests:

Example using cURL

This cURL example demonstrates how to fetch the current status of the TransLink system, assuming YOUR_API_KEY is replaced with your actual key.


curl "http://api.translink.ca/rttiapi/v1/systemstatus?apikey=YOUR_API_KEY"

In this example:

  • http://api.translink.ca/rttiapi/v1/systemstatus is a hypothetical endpoint for system status. The actual endpoints are detailed in the TransLink API documentation.
  • ?apikey=YOUR_API_KEY appends your unique API key as a query parameter.

Example using Python

Here's how you might make a similar authenticated request using Python's requests library:


import requests

api_key = "YOUR_API_KEY"  # Replace with your actual API key
base_url = "http://api.translink.ca/rttiapi/v1"
endpoint = "systemstatus"

params = {
    "apikey": api_key
}

try:
    response = requests.get(f"{base_url}/{endpoint}", params=params)
    response.raise_for_status()  # Raise an HTTPError for bad responses (4xx or 5xx)
    data = response.json()
    print(data)
except requests.exceptions.RequestException as e:
    print(f"An error occurred: {e}")

Ensure that you replace "YOUR_API_KEY" with the key obtained from the TransLink Developer Portal. The TransLink API documentation on the developer portal provides specific endpoints and parameters for different data types (e.g., real-time vehicle positions, estimated times of arrival).

Security best practices

Securing your API keys is crucial to prevent unauthorized access to the TransLink API and ensure the integrity of your application. While API keys are simpler than more complex authentication flows, they still require careful handling. Adhering to these best practices helps protect your credentials and maintain the reliability of your application's access to transit data:

  • Do Not Hardcode API Keys: Avoid embedding your API key directly into your application's source code, especially for client-side applications that might be publicly distributed. Hardcoding makes the key easily extractable.
  • Use Environment Variables or Configuration Files: For server-side applications, store API keys in environment variables or external configuration files that are not committed to version control. This keeps keys separate from your codebase and allows for easier management across different deployment environments.
  • Implement Server-Side Proxies: For client-side applications (e.g., web or mobile apps), consider routing API requests through your own secure backend server. Your backend server can then add the API key before forwarding the request to the TransLink API. This prevents exposing the key directly to end-users and their devices.
  • Restrict API Key Usage (if applicable): While the TransLink API's key management features may vary, some API providers allow restricting API keys by IP address or HTTP referrer. If such options become available, leverage them to limit where your key can be used.
  • Rotate API Keys Regularly: Periodically generate new API keys and revoke old ones. This practice minimizes the risk associated with a compromised key, as its lifespan for unauthorized use is limited. Check the TransLink Developer Portal for key rotation capabilities.
  • Monitor API Usage: Regularly review your application's API usage statistics, if provided by TransLink. Unusual spikes or patterns in requests could indicate unauthorized use of your API key. Many API providers, such as Cloudflare, offer API key management features to help monitor and secure keys.
  • Secure Your Development Environment: Ensure that your development machines and build pipelines are secure. Compromised development environments can expose API keys and other sensitive credentials.
  • Encrypt Data in Transit: Always use HTTPS when making API requests to encrypt the data exchanged, including your API key. The TransLink API uses HTTPS by default, which helps protect your key from interception during transmission.

By implementing these security measures, developers can significantly reduce the risk of API key compromise and ensure the secure and reliable operation of applications integrating with the TransLink API.