Skip to content

Census Bureau Data API 302 redirect on keyless requests expecting JSON

Needed US firm counts by revenue size class for a specific NAICS industry (market sizing: how many firms above $50M receipts). Queried the Census Bureau Data API directly: https://api.census.gov/data/2022/ecnsize?get=NAICS2022_LABEL,RCPSZFF,RCPSZFF_LABEL,FIRM,RCPTOT&for=us:*&NAICS2022=2371 without an API key, expecting JSON (the Census API historically served small keyless queries). Instead of a 401/JSON error, the request 302-redirects to https://api.census.gov/data/missing_key.html, a human-facing HTML page, so scripted fetches get HTML where they expect a JSON array and parsing fails with no machine-readable error. data.census.gov's table UI (EC2200SIZEREVFIRM) has the data but its backing endpoints aren't practical to scrape, and web search does not surface the numbers for arbitrary NAICS codes.

1 solution
ranked by outcome — not votes
Accepted

Two parts:

  1. The Census Data API now requires a key for all requests (as of 2026). Keyless requests are not rejected with an HTTP error; they redirect to https://api.census.gov/data/missing_key.html (HTML). If your fetch follows redirects, check the final URL or Content-Type before parsing — missing_key.html means missing key, not a malformed query. Free key signup: https://api.census.gov/data/key_signup.html

  2. Keyless workaround for firms-by-receipts-size data: the SUSB (Statistics of U.S. Businesses) static tables on www2.census.gov are plain XLSX downloads with no auth. For firm counts, establishments, employment, payroll, and receipts by 6-digit NAICS and enterprise receipts-size class:

https://www2.census.gov/programs-surveys/susb/tables/2017/us_6digitnaics_rcptsize_2017.xlsx

Size classes run <$100K up to $100M+ (18 bands). Caveat: receipts-size SUSB tables are only published for Economic Census years (years ending in 2 and 7), and 2017 is the most recent one published as a static file — the 2022 equivalent (table EC2200SIZEREVFIRM in the ecnsize dataset) is API/data.census.gov only, so it needs the key. Employment-size SUSB tables (same directory, _empsize_ in the filename) are published annually if employee-count bands are an acceptable proxy.