Getting started overview

The Covid Tracking Project offers historical data related to the COVID-19 pandemic within the United States. Unlike many APIs that necessitate an account, API keys, or authentication tokens, the Covid Tracking Project’s API is publicly accessible and entirely free to use. This design choice streamlines the onboarding process, allowing developers, researchers, and journalists to retrieve data directly from the available endpoints without prior registration.

The project officially ceased active data collection on March 7, 2021. However, all historical data collected up to that date remains available through its API. This makes it a valuable resource for studies, analyses, and applications focusing on the pandemic's early and middle phases in the US.

Before making a request, identify the specific data you need. The API provides various endpoints for state-level data, including daily reports, historical series, and specific metrics like positive cases, hospitalizations, and deaths. Familiarize yourself with the Covid Tracking Project API documentation to understand the available data structures and query parameters.

Quick Start Steps
Step What to do Where
1 Review API Documentation Covid Tracking Project API documentation
2 No Account/Keys Needed Direct API access
3 Construct Your First Request Your preferred HTTP client (e.g., cURL, Python requests, browser)
4 Process Data Your application environment

Create an account and get keys

Accessing the Covid Tracking Project API does not require an account, API keys, or any form of authentication. The data is made available publicly to support research and public understanding. This means you can proceed directly to constructing your API requests without any signup process. This approach eliminates common setup hurdles, such as managing API keys or handling authentication tokens, simplifying the initial integration for developers.

The project's commitment to open data means that all data endpoints are designed for direct public access. This policy minimizes barriers to entry, aligning with the project's goal of providing timely and accessible information during the pandemic. For more details on this open access policy, refer to the Covid Tracking Project API overview.

Your first request

To make your first request to the Covid Tracking Project API, you can use any HTTP client. The API primarily returns data in JSON format, which is widely supported across programming languages and tools.

Endpoint structure

The base URL for the API is https://api.covidtracking.com/v1/. Specific data is then accessed via additional paths (e.g., states/daily, us/daily).

Example: Get all states' historical daily data

One of the most comprehensive datasets available is the historical daily data for all US states. You can access this via the /states/daily endpoint. This endpoint provides a JSON array where each object represents a state's data for a specific day.

cURL example

Using cURL, a common command-line tool for making HTTP requests:

curl "https://api.covidtracking.com/v1/states/daily.json"

Python example

Using Python with the requests library:

import requests
import json

url = "https://api.covidtracking.com/v1/states/daily.json"
response = requests.get(url)

if response.status_code == 200:
    data = response.json()
    # Print the first few entries to verify data retrieval
    print(json.dumps(data[:5], indent=2))
else:
    print(f"Error: {response.status_code}")
    print(response.text)

JavaScript (Node.js/Browser) example

Using JavaScript with fetch (Node.js or browser environment):

fetch('https://api.covidtracking.com/v1/states/daily.json')
  .then(response => {
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    return response.json();
  })
  .then(data => {
    // Log the first few entries to verify data retrieval
    console.log(data.slice(0, 5));
  })
  .catch(error => console.error('Error fetching data:', error));

Expected response structure

The response for the /states/daily.json endpoint is a JSON array of objects. Each object typically contains fields such as:

  • date (integer): Date in YYYYMMDD format.
  • state (string): State postal code (e.g., "NY", "CA").
  • positive (integer): Total positive cases.
  • hospitalizedCumulative (integer): Cumulative hospitalizations.
  • death (integer): Total deaths.
  • dataQualityGrade (string): A letter grade indicating data quality.

For a complete list of fields and their descriptions, consult the Covid Tracking Project states daily API reference.

Common next steps

After successfully making your first request and retrieving data from the Covid Tracking Project API, consider these common next steps to integrate the data into your projects:

  1. Explore Specific Endpoints: The API offers various endpoints for more granular data. For example, you can query data for a specific state or a specific date. Review the Covid Tracking Project API v1 reference to identify endpoints relevant to your project, such as /states/{stateAbbr}/daily.json for a single state's daily data or /us/daily.json for US aggregate data.

  2. Data Parsing and Storage: The API returns data in JSON format. You will likely need to parse this JSON and integrate it into your application's data structures or store it in a database for further analysis. Libraries like Python's pandas or R's jsonlite package can assist with data manipulation and analysis.

  3. Data Visualization: Historical COVID-19 data is highly suitable for visualization. Tools such as Matplotlib, Seaborn in Python, ggplot2 in R, or D3.js in JavaScript can be used to create charts, graphs, and maps illustrating trends, comparisons, and impacts over time.

  4. Integration with Other Data Sources: Combine Covid Tracking Project data with other public health or demographic datasets to enrich your analysis. For example, you might integrate with US Census Bureau data for population context or NOAA data for environmental factors. The ability to integrate public health data with other datasets is a common practice in data science, as described in Google Cloud's public datasets documentation.

  5. Automate Data Retrieval: While the project is no longer actively collecting new data, if your application requires periodic refreshes of the historical dataset (e.g., to ensure data integrity or for specific analytical workflows), consider scheduling scripts to fetch data. Be mindful that the historical data does not change post-March 7, 2021.

  6. Error Handling: Implement robust error handling in your application to manage potential network issues, malformed responses, or other unexpected events. While the Covid Tracking Project API is generally stable for historical data, good error handling practices are crucial for any external API integration.

Troubleshooting the first call

When making your first API call to the Covid Tracking Project, you might encounter issues. Here are common problems and troubleshooting steps:

1. Network connectivity issues

  • Problem: Your client cannot reach the API server.
  • Troubleshooting:
    • Verify your internet connection.
    • Check if the Covid Tracking Project API server is reachable by attempting to access https://api.covidtracking.com/ directly in your web browser.
    • Check for any local firewall or proxy settings that might be blocking outbound HTTP requests from your environment.

2. Incorrect URL or endpoint

  • Problem: You receive a 404 Not Found error or an empty response.
  • Troubleshooting:
    • Double-check the API endpoint URL for typos. For instance, ensure you are using /v1/states/daily.json and not an incorrect variation.
    • Refer to the official API documentation for the exact endpoint paths.
    • Ensure you are requesting the correct file type (e.g., .json or .csv) if specified in the endpoint.

3. JSON parsing errors

  • Problem: Your programming language's JSON parser fails, or the data structure is not what you expect.
  • Troubleshooting:
    • Inspect the raw API response using tools like curl or your browser's developer console to ensure it's valid JSON.
    • If the response is not JSON (e.g., an HTML error page), it might indicate a different underlying issue (e.g., 404 or 500 server error).
    • Ensure your code correctly handles potential empty arrays or null values for specific fields, as data completeness varied across states and dates.

4. Outdated data expectation

  • Problem: Expecting real-time updates or data beyond March 7, 2021.
  • Troubleshooting:
    • Remember that the Covid Tracking Project ceased active data collection on March 7, 2021. The API provides historical data up to that point only.
    • If you need more current data, you will need to explore alternative data sources like Our World in Data or other active public health dashboards.

5. HTTP status codes

  • Problem: Receiving an HTTP status code other than 200 OK.
  • Troubleshooting:
    • 400 Bad Request: Although less common for this API without parameters, it suggests an invalid request.
    • 403 Forbidden: Indicates access denied. However, this should not occur for the Covid Tracking Project API as it's public. If seen, investigate network or proxy issues.
    • 404 Not Found: The requested resource does not exist. Check your URL.
    • 5xx Server Error: An issue on the API server side. These are typically temporary. Wait and retry your request.