Bureau of Labor Statistics’ API - api

Data - BLS


Code
# cd ~/iCloud/website/data; Rscript --vanilla _update_qmd_folder.R bls only=api.qmd
# sh ~/iCloud/website/website_short.sh
here::i_am("data/bls/api.qmd")
source(here::here("code", "R-markdown", "init_insee.R"))

# The blsAPI package (mikeasilva/blsAPI, GitHub-only, archived from CRAN in
# 2023) used to wrap these calls. It is replaced here by direct httr/jsonlite
# requests against the public BLS API v1 (no registration key -- limits: 25
# series and 10 years per request, 25 requests/day), matching the pattern
# the other api.qmd pages use.
bls_series <- function(seriesid, startyear = NULL, endyear = NULL) {
  base <- "https://api.bls.gov/publicAPI/v1/timeseries/data/"
  if (length(seriesid) == 1 && is.null(startyear) && is.null(endyear)) {
    resp <- httr::GET(paste0(base, seriesid))
  } else {
    body <- list(seriesid = as.list(seriesid))
    if (!is.null(startyear)) body$startyear <- as.character(startyear)
    if (!is.null(endyear))   body$endyear   <- as.character(endyear)
    resp <- httr::POST(base,
                       body = jsonlite::toJSON(body, auto_unbox = TRUE),
                       httr::content_type_json())
  }
  parsed <- httr::content(resp, "text", encoding = "UTF-8") |>
    jsonlite::fromJSON(flatten = TRUE)
  if (!identical(parsed$status, "REQUEST_SUCCEEDED"))
    stop(paste(parsed$message, collapse = "; "))

  series <- parsed$Results$series
  purrr::map_dfr(seq_len(nrow(series)), function(i) {
    d <- series$data[[i]]
    if (is.null(d) || length(d) == 0) return(tibble::tibble())
    tibble::as_tibble(d) |>
      dplyr::transmute(seriesID = series$seriesID[i],
                       year, period, periodName,
                       value = as.numeric(value)) |>
      dplyr::arrange(year, period)
  })
}

# QCEW slices are served as plain CSV from a separate endpoint (no key).
bls_qcew_industry <- function(year, quarter, industry) {
  readr::read_csv(
    sprintf("https://data.bls.gov/cew/data/api/%s/%s/industry/%s.csv",
            year, quarter, industry),
    show_col_types = FALSE)
}

Info

List of APIs

source dataset Title Updated
bdf api Banque de France's API - api 2026-09-09
bea api Bureau of Economic Analysis' API - api 2026-09-11
bis api Bank of International Settlements' API - api 2026-09-11
bls api Bureau of Labor Statistics' API - api 2026-09-09
dbnomics api DBnomics' API - api 2026-09-09
ecb api European Central Bank's API - api 2026-09-09
eurostat api Eurostat's API - api 2026-09-11
imf api International Monetary Fund's API - api 2026-09-11
insee api Institut National de la Statistique et des Etudes Economiques' API - api 2026-09-09
oecd api OECD's API - api 2026-08-02
wdi api World Development Indicators' API - api 2026-09-11

Documentation: BLS Public Data API, signatures v1 & v2.

BLS API

Registering for an API key (v2) lifts most limits: https://data.bls.gov/registrationEngine/. The calls below use the keyless v1 API.

Retrieve a series

Code
data <- bls_series("LAUCN040010000000005")

data |>
  print_table_conditional()

California Unemployment rate

One (very) annoying limitation of the keyless BLS API (v1) is that you can only retrieve up to 10 years of data per request (20 years with a v2 registration key).

Code
data <- bls_series(c("LASST050000000000003", "LASST060000000000003"),
                   startyear = 2009,
                   endyear   = 2018)

data |>
  head(10) |>
  print_table_conditional()
seriesID year period periodName value
LASST050000000000003 2009 M01 January 7.0
LASST050000000000003 2009 M02 February 7.3
LASST050000000000003 2009 M03 March 7.6
LASST050000000000003 2009 M04 April 7.8
LASST050000000000003 2009 M05 May 7.9
LASST050000000000003 2009 M06 June 7.9
LASST050000000000003 2009 M07 July 7.9
LASST050000000000003 2009 M08 August 7.8
LASST050000000000003 2009 M09 September 7.8
LASST050000000000003 2009 M10 October 7.8

BLS QCEW

Code
# Example: Construction data (industry 1012) for the first quarter of 2017
Construction <- bls_qcew_industry(year = "2017", quarter = "1", industry = "1012")

Construction |>
  head(10) |>
  print_table_conditional()
area_fips own_code industry_code agglvl_code size_code year qtr disclosure_code qtrly_estabs month1_emplvl month2_emplvl month3_emplvl total_qtrly_wages taxable_qtrly_wages qtrly_contributions avg_wkly_wage lq_disclosure_code lq_qtrly_estabs lq_month1_emplvl lq_month2_emplvl lq_month3_emplvl lq_total_qtrly_wages lq_taxable_qtrly_wages lq_qtrly_contributions lq_avg_wkly_wage oty_disclosure_code oty_qtrly_estabs_chg oty_qtrly_estabs_pct_chg oty_month1_emplvl_chg oty_month1_emplvl_pct_chg oty_month2_emplvl_chg oty_month2_emplvl_pct_chg oty_month3_emplvl_chg oty_month3_emplvl_pct_chg oty_total_qtrly_wages_chg oty_total_qtrly_wages_pct_chg oty_taxable_qtrly_wages_chg oty_taxable_qtrly_wages_pct_chg oty_qtrly_contributions_chg oty_qtrly_contributions_pct_chg oty_avg_wkly_wage_chg oty_avg_wkly_wage_pct_chg
01000 3 1012 53 0 2017 1 N 3 0 0 0 0 0 0 0 N 0.05 0.00 0.00 0.00 0.00 0.00 0.00 0.00 N 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
01000 5 1012 53 0 2017 1 NA 9418 83172 83992 85415 1090022541 623745976 15390351 996 NA 0.96 0.96 0.96 0.95 1.05 0.96 1.00 1.10 NA 210 2.3 353 0.4 1208 1.5 834 1.0 87644260 8.7 22362749 3.7 -2418247 -13.6 71 7.7
01001 5 1012 73 0 2017 1 NA 79 443 434 424 4508287 2900721 51398 800 NA 1.16 0.91 0.88 0.85 0.93 0.96 0.68 1.06 NA -2 -2.5 7 1.6 -6 -1.4 -15 -3.4 121174 2.8 15737 0.5 -14955 -22.5 30 3.9
01003 5 1012 73 0 2017 1 NA 572 3621 3623 3645 41852796 26384742 386967 887 NA 1.21 1.17 1.15 1.10 1.49 1.16 0.83 1.31 NA 30 5.5 217 6.4 206 6.0 60 1.7 6352836 17.9 2666038 11.2 -38263 -9.0 100 12.7
01005 5 1012 73 0 2017 1 NA 30 144 151 152 2248580 963074 11157 1161 NA 0.68 0.40 0.41 0.41 0.68 0.36 0.20 1.66 NA -2 -6.2 -9 -5.9 4 2.7 2 1.3 386568 20.8 20912 2.2 -5875 -34.5 206 21.6
01007 5 1012 73 0 2017 1 NA 31 628 615 706 10215205 5174429 139467 1210 NA 1.09 3.39 3.29 3.65 5.42 4.26 4.21 1.57 NA 2 6.9 -126 -16.7 -123 -16.7 -104 -12.8 -1001795 -8.9 -952161 -15.5 -28136 -16.8 86 7.7
01009 5 1012 73 0 2017 1 NA 89 483 496 491 4524333 3173331 56491 710 NA 1.47 1.30 1.32 1.28 1.40 1.31 1.28 1.07 NA 10 12.7 62 14.7 64 14.8 55 12.6 773109 20.6 500248 18.7 10787 23.6 38 5.7
01011 5 1012 73 0 2017 1 N 4 0 0 0 0 0 0 0 N 0.35 0.00 0.00 0.00 0.00 0.00 0.00 0.00 N -1 -20.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
01013 5 1012 73 0 2017 1 NA 26 198 197 191 2275535 1408889 30673 896 NA 0.68 0.65 0.64 0.61 0.89 0.61 0.54 1.41 NA -1 -3.7 -40 -16.8 -40 -16.9 -37 -16.2 -271954 -10.7 -181999 -11.4 -13977 -31.3 60 7.2
01015 5 1012 73 0 2017 1 NA 157 853 857 851 9055626 5689071 133766 816 NA 0.79 0.43 0.43 0.41 0.45 0.45 0.42 1.07 NA 6 4.0 67 8.5 58 7.3 44 5.5 983511 12.2 406766 7.7 -14851 -10.0 37 4.7