Getting started overview

The Brazilian Chamber of Deputies Open Data API provides direct, public access to a range of legislative information. This includes details about federal deputies, proposed legislation (propositions), voting records, and parliamentary events. As a fully free and open resource, it does not require an API key or account registration, simplifying the initial setup process for developers and researchers alike. The API is designed to support government transparency initiatives and facilitate the development of civic technology applications.

Interacting with the API primarily involves sending standard HTTP GET requests to specific endpoints. The API's responses are typically formatted in JSON, a common data interchange format supported by most programming languages and web browsers. The official documentation, available in Portuguese, includes an interactive Swagger UI, which allows users to explore available endpoints, understand request parameters, and test queries directly from a web browser. This guide focuses on the immediate steps to make your first successful data retrieval.

Quick Reference Steps

Step What to Do Where
1. Review Documentation Familiarize yourself with API structure and endpoints. Brazilian Chamber of Deputies Open Data documentation
2. Explore Endpoints Use the interactive interface to see available resources. Brazilian Chamber of Deputies Open Data Swagger UI
3. Formulate Request Choose an endpoint and construct your first HTTP GET request. Your preferred HTTP client or browser
4. Execute Request Send the GET request to retrieve data. Your preferred HTTP client or browser
5. Process Response Parse the JSON response to extract relevant information. Your application logic

Create an account and get keys

The Brazilian Chamber of Deputies Open Data API operates on a public access model, meaning it does not require developers to create an account or obtain API keys for access. All data endpoints are openly available for consumption without any authentication mechanisms. This simplifies the onboarding process significantly, as there are no credentials to manage or rate limits tied to individual keys.

Developers can begin making requests immediately after reviewing the available documentation and understanding the API's structure. This open access model aligns with principles of government transparency, aiming to make legislative information as broadly accessible as possible. For developers accustomed to APIs that require authentication, this means bypassing typical setup steps such as:

  • Registering on a developer portal.
  • Generating API keys or client secrets.
  • Implementing OAuth 2.0 flows or other authentication protocols.

While the absence of keys streamlines access, it is important to note that developers should still adhere to good practices for consuming public APIs, such as implementing appropriate request throttling on their end to avoid overloading the server, even if no explicit rate limits are enforced at the API level. General best practices for API consumption include implementing exponential backoff for retries to handle transient network issues, as described in Google Cloud's retry strategy documentation.

Your first request

To make your first request to the Brazilian Chamber of Deputies Open Data API, you will construct a simple HTTP GET request to one of its public endpoints. We will use the endpoint for listing federal deputies as an example, as it provides a straightforward way to retrieve a list of current legislators.

Endpoint Example: List Deputies

The base URL for the API is https://dadosabertos.camara.leg.br/api/v2/. A common starting point is the /deputados endpoint, which returns a list of federal deputies.

Request URL:

GET https://dadosabertos.camara.leg.br/api/v2/deputados

You can execute this request using various tools:

Using a Web Browser

Open your web browser and navigate to: https://dadosabertos.camara.leg.br/api/v2/deputados. The browser will display the JSON response directly. This is the simplest way to confirm connectivity and view raw data.

Using curl (Command Line)

Open your terminal or command prompt and enter the following command:

curl "https://dadosabertos.camara.leg.br/api/v2/deputados"

This command will print the JSON response directly to your terminal. For better readability, you might pipe the output to a JSON formatter:

curl "https://dadosabertos.camara.leg.br/api/v2/deputados" | python -m json.tool

Using Python

If you are using Python, you can make the request with the requests library:


import requests
import json

url = "https://dadosabertos.camara.leg.br/api/v2/deputados"
response = requests.get(url)

if response.status_code == 200:
    deputies_data = response.json()
    # Print the first few deputies to verify
    for deputy in deputies_data['dados'][:3]:
        print(f"ID: {deputy['id']}, Name: {deputy['nome']}")
else:
    print(f"Error: {response.status_code}")
    print(response.text)

This Python script will fetch the data, parse the JSON, and print the IDs and names of the first three deputies, providing a programmatic confirmation of your successful request.

Common next steps

After successfully retrieving data from the Brazilian Chamber of Deputies Open Data API, several common next steps can enhance your application or research project:

  1. Explore More Endpoints: The API offers a wide range of data beyond just deputies. Investigate endpoints for propositions (/proposicoes), voting events (/eventos), and legislative expenses. The interactive Swagger UI is the best tool for discovering these resources and understanding their parameters.

  2. Implement Filtering and Pagination: Many endpoints support query parameters for filtering results (e.g., by nome, siglaPartido, dataInicio, dataFim) and pagination (pagina, itens). Integrating these parameters allows you to retrieve specific subsets of data efficiently, reducing the amount of data transferred and processed. For example, to get deputies from a specific party, you might use /deputados?siglaPartido=PT.

  3. Data Processing and Storage: Depending on your application's needs, you might want to process the retrieved JSON data, transform it, and store it in a database for faster querying or offline analysis. Consider using libraries specific to your programming language for JSON parsing and database interaction.

  4. Error Handling: While the API is publicly accessible, robust applications should include error handling for network issues, unexpected response formats, or potential server-side errors. Check HTTP status codes (e.g., 200 OK, 404 Not Found, 500 Internal Server Error) and implement retry mechanisms for transient failures, following principles outlined in MDN Web Docs on HTTP status codes.

  5. Build a User Interface or Application: For civic tech projects, the next step is often to integrate the API data into a user-facing application, dashboard, or data visualization tool. This could involve web development frameworks (e.g., React, Vue, Angular) or data visualization libraries (e.g., D3.js, Chart.js).

  6. Monitor for Updates: Legislative data can change frequently. If your application requires up-to-date information, consider implementing a strategy for regularly fetching and refreshing data. This might involve scheduled tasks or webhooks if the API were to offer them (though currently, it primarily supports polling).

Troubleshooting the first call

When making your first API call, you might encounter issues. Here are common problems and their solutions:

  • Network Connectivity Issues:

    • Symptom: No response, connection timeout, or DNS resolution failure.
    • Solution: Verify your internet connection. Check if you can access other websites. Ensure the API domain dadosabertos.camara.leg.br is reachable. Temporarily disable any VPNs or firewalls that might be blocking outbound HTTP requests.
  • Incorrect URL or Endpoint:

    • Symptom: HTTP 404 Not Found error or an empty/unexpected JSON response.
    • Solution: Double-check the URL for typos. Refer to the Swagger UI to confirm the exact endpoint path and base URL. Ensure you are using https.
  • JSON Parsing Errors:

    • Symptom: Your code fails when trying to parse the API response, reporting invalid JSON.
    • Solution: The API typically returns valid JSON. This error often indicates that the response was not JSON (e.g., an HTML error page from a 404, or an empty response). First, inspect the raw response content to see what was actually returned. Ensure your HTTP client is correctly interpreting the response headers. If using curl, check the output directly. If using a programming language, print the raw response.text before attempting response.json().
  • Rate Limiting (Informal):

    • Symptom: Occasional HTTP 429 Too Many Requests, or slow responses after many rapid requests, even though no official rate limits are documented.
    • Solution: While the API does not publish explicit rate limits, excessive requests in a short period might lead to temporary blocking or degraded performance. Implement a delay between your requests, especially in loops, to avoid overwhelming the server. Consider an exponential backoff strategy if you encounter repeated failures.
  • Outdated Documentation Reference:

    • Symptom: An endpoint described in older documentation no longer works or returns different data.
    • Solution: Always refer to the most current official documentation and the Swagger UI, as API structures can evolve over time.