Getting started overview

The Federal Election Commission (FEC) API offers public access to federal campaign finance data, including information on candidates, committees, contributions, and expenditures. This guide outlines the process for obtaining an API key and making your initial request. The FEC API is designed for developers, researchers, and journalists seeking to integrate campaign finance data into applications, analyses, or reports.

To access the data, you will need to register for a free API key. This key authenticates your requests and helps the FEC manage usage. Once you have the key, you can construct API calls using standard HTTP methods to retrieve specific datasets. The API supports various parameters for filtering and searching, allowing precise data retrieval based on criteria such as election cycle, candidate name, or committee type. The documentation provides interactive examples and a sandbox environment to test requests before full implementation. This quickstart focuses on the fundamental steps to ensure a successful first interaction with the FEC API.

Quick reference table

Step What to do Where
1. Sign Up Register for a free account. FEC Developer Portal signup
2. Get API Key Request your unique API key. FEC API Key request form
3. Make Request Construct and send your first API call. Your preferred HTTP client (e.g., curl, Python requests, JavaScript fetch)
4. Parse Response Process the JSON data returned. Your application logic

Create an account and get keys

Access to most FEC API endpoints requires an API key. This key is free and serves to identify your application and enable rate limiting. Follow these steps to obtain your key:

  1. Navigate to the FEC Developer Portal: Open your web browser and go to the official FEC developer documentation page.
  2. Locate the API Key Request Section: On the developer portal, look for a section specifically for obtaining an API key. This is usually labeled "Get an API key" or similar.
  3. Fill out the Request Form: You will be prompted to provide an email address. The FEC uses this email to send your API key and communicate any updates. Ensure the email address is valid and accessible.
  4. Submit the Form: After entering your email, submit the form. The API key is typically sent to your provided email address within a few minutes.
  5. Retrieve Your API Key: Check your inbox (and spam folder) for an email from the FEC containing your unique API key. This key is a long alphanumeric string. Keep this key secure, as it grants access to the FEC API.

The FEC API key is a simple token that you include with each request. Unlike more complex authentication mechanisms like OAuth 2.0, which often involve multiple steps for token exchange, the FEC API uses a direct approach. The key can be passed as a query parameter or an HTTP header, offering flexibility in integration. For example, the OAuth 2.0 framework, used by many commercial APIs, involves authorization servers and client credentials to issue access tokens, a more complex process than the FEC's public API key system.

Your first request

Once you have your API key, you can make your first request to the FEC API. This example demonstrates how to retrieve a list of candidates from the 2022 election cycle using curl and Python.

API key placement

The FEC API expects the API key to be included as a query parameter named api_key in your request URL. For example:

GET /v1/candidates/?api_key=YOUR_API_KEY&cycle=2022 HTTP/1.1
Host: api.open.fec.gov

Example 1: Using curl

curl is a command-line tool for making HTTP requests. Replace YOUR_API_KEY with the actual key you received.

curl "https://api.open.fec.gov/v1/candidates/?api_key=YOUR_API_KEY&cycle=2022&per_page=5"

This command requests 5 candidates from the 2022 election cycle. The response will be a JSON object containing candidate data.

Example 2: Using Python

The Python requests library simplifies making HTTP requests. Install it if you haven't:

pip install requests

Then, use the following Python code:

import requests
import json

API_KEY = "YOUR_API_KEY"  # Replace with your actual API key
BASE_URL = "https://api.open.fec.gov/v1/candidates/"

params = {
    "api_key": API_KEY,
    "cycle": 2022,
    "per_page": 5
}

try:
    response = requests.get(BASE_URL, params=params)
    response.raise_for_status()  # Raise an HTTPError for bad responses (4xx or 5xx)
    data = response.json()

    print("Successfully retrieved candidates:")
    # Pretty print the JSON response for readability
    print(json.dumps(data, indent=2))

except requests.exceptions.HTTPError as errh:
    print(f"HTTP Error: {errh}")
except requests.exceptions.ConnectionError as errc:
    print(f"Error Connecting: {errc}")
except requests.exceptions.Timeout as errt:
    print(f"Timeout Error: {errt}")
except requests.exceptions.RequestException as err:
    print(f"An unexpected error occurred: {err}")

This Python script fetches 5 candidates from the 2022 cycle and prints the JSON response. The response.raise_for_status() call is crucial for identifying HTTP errors, as described in the MDN Web Docs on HTTP status codes.

Common next steps

After successfully making your first request, consider these common next steps to further explore and utilize the FEC API:

  • Explore Endpoints: Review the FEC API documentation to discover other available endpoints, such as those for committees, filings, and financial summaries. Each endpoint provides access to different datasets.
  • Implement Pagination: For larger datasets, learn how to use pagination parameters (e.g., page, per_page) to retrieve results in manageable chunks. This prevents overwhelming your application and adheres to API rate limits.
  • Filter and Search: Experiment with various query parameters to filter data by specific criteria (e.g., candidate_id, committee_type, min_date, max_date). The documentation details all available filters for each resource.
  • Handle Rate Limits: The FEC API has rate limits to ensure fair usage. Implement logic in your application to handle 429 Too Many Requests responses, potentially by introducing delays between calls or retrying requests with an exponential backoff strategy. Information on rate limits is usually found within the API's usage policy or FAQ sections.
  • Use an SDK (Python): If working with Python, consider using the community-contributed Python SDK to simplify interactions with the API. While not officially maintained by the FEC, it can abstract away direct HTTP requests, as many vendor-provided SDKs like AWS's Boto3 do for their services.
  • Error Handling: Enhance your application's error handling to gracefully manage common API errors, such as invalid parameters or server issues, providing informative feedback to users or logging details for debugging.
  • Data Storage and Analysis: Decide how you will store the retrieved data (e.g., in a database, flat files) and what tools you will use for analysis (e.g., Pandas in Python, SQL queries, spreadsheet software).

Troubleshooting the first call

If your first API call doesn't return the expected results, consider these common troubleshooting steps:

  • Invalid API Key: Double-check that you have correctly copied and pasted your API key. Even minor typos can cause authentication failures. Ensure there are no extra spaces or characters. The FEC API will typically return a 401 Unauthorized or 403 Forbidden status code if the key is invalid or missing.
  • Missing API Key: Confirm that the api_key parameter is present in your request URL. The API will not process requests without it.
  • Incorrect Endpoint URL: Verify that the base URL and endpoint path are correct (e.g., https://api.open.fec.gov/v1/candidates/). Refer to the FEC API reference documentation for exact endpoint paths.
  • HTTP Status Codes: Pay attention to the HTTP status code returned in the API's response. Common codes to look for include:
    • 200 OK: Success. The request was processed, and data is returned.
    • 400 Bad Request: Often indicates an issue with your query parameters (e.g., missing a required parameter, invalid parameter value). Review the documentation for the specific endpoint.
    • 401 Unauthorized / 403 Forbidden: Typically means your API key is invalid or you lack permission to access the requested resource.
    • 404 Not Found: The requested resource does not exist, often due to an incorrect URL path.
    • 429 Too Many Requests: You have exceeded the API's rate limit. Wait for some time before making further requests.
    • 5xx Server Error: An issue on the FEC API server side. These are usually temporary; try again later.
  • Parameter Mismatch: Ensure that the query parameters you are sending match those expected by the API (e.g., cycle instead of election_year). Parameter names are case-sensitive. The OpenAPI Specification, which many APIs follow, emphasizes precise parameter definitions.
  • Network Issues: Check your internet connection. A common troubleshooting step for any API call is to ensure network connectivity, as described in debugging guides for tools like Chrome DevTools network panel.
  • JSON Parsing Errors: If you receive a successful response (200 OK) but cannot parse the data, ensure your parsing logic is correct. The FEC API returns data in JSON format, so use a robust JSON parser.

By systematically checking these points, you can often diagnose and resolve issues with your first FEC API calls.