Represent Civic Information API

Data Access

Explore Canada's OpenNorth Represent API

The OpenNorth Represent API is a public web service that provides Canadian government data in a standardized and accessible format. By using this API, you can access data from a variety of sources, including federal, provincial, and municipal government websites.

Here's how to get started exploring Canada's OpenNorth Represent API using JavaScript:

Step 1: Register for an API key

Before you can start using the OpenNorth Represent API, you'll need to register for an API key. This key will allow you to access the data on the Represent website. You can register for an API key here.

Step 2: Make API requests

Now that you have your API key, you can start making requests to the Represent API. The API has a number of endpoints that you can access, including:

  • Postal codes
  • Electoral districts
  • Representatives
  • Political parties

Here is an example of how to access the postal codes endpoint using the JavaScript fetch API:

const apiKey = 'your_api_key_here';
const postalCode = 'K1A0A4';

fetch(`https://represent.opennorth.ca/postcodes/${postalCode}/?sets=federal-electoral-districts&key=${apiKey}`)
  .then(response => response.json())
  .then(data => console.log(data));

This example fetches data for the postal code K1A0A4 and includes data for federal electoral districts. Notice that you need to include your API key in the request URL using the key parameter.

Step 3: Parse API responses

Once you've made a request to the OpenNorth Represent API, you'll receive a response containing the data you requested. The response will be in JSON format, which means you can parse it into a JavaScript object using the JSON.parse() method.

Here's an example of how to parse the response from the previous example:

const apiKey = 'your_api_key_here';
const postalCode = 'K1A0A4';

fetch(`https://represent.opennorth.ca/postcodes/${postalCode}/?sets=federal-electoral-districts&key=${apiKey}`)
  .then(response => response.json())
  .then(data => {
    const districts = data['representatives_centroid'];
    districts.forEach(district => {
      console.log(district.name);
    });
  });

This example parses the response and then iterates over the federal electoral districts in the response, logging the name of each district to the console.

Conclusion

That's it! This short guide should help you get started exploring Canada's OpenNorth Represent API using JavaScript. Remember to read the API documentation carefully to ensure you're making proper requests and parsing responses correctly. Happy exploring!

Related APIs

Public APIs — A directory of free and public apis

Built by @mddanishyusuf