bls-api-key: Managing API keys

bls-api-keyR Documentation

Managing API keys

Description

It is strongly recommended users of the BLS API use an API key. This key can be stored as environment variable, BLS_API_KEY.

  • bls_get_key() will retrieve the key, if set, or it will return NULL if the key has not been set or has been unset.

  • bls_set_key() will set the key for the current R session. For persistence across sessions, set the environment variable. See the Persistence section for more information.

  • bls_unset_key() will unset the key for the current R session.

  • bls_has_key() returns TRUE if a key can be found. Otherwise it returns FALSE.

Usage

bls_set_key(key)

bls_unset_key()

bls_get_key()

bls_has_key()

Arguments

key

A valid BLS API key as a string. keys are typically 32 characters in length and a key with a different length will trigger a warning.

Registering for and using an API key

Registering for an API key is not required to use the BLS API, but it is recommended you register for an API key and use it. Requests without a key are limited to 10 years of data per request, 25 series per query, and 25 queries per day. You can register for an API key at: https://data.bls.gov/registrationEngine/

Persistence

The preferred method to set the key is to set the BLS_API_KEY environment variable in an .Renviron file. The easiest way to do this is by calling usethis::edit_r_environ(). Don't forget to restart R after setting the key.

See Also

Other blsR-utils: data_as_table(), data_as_tidy_table(), merge_tables(), merge_tidy_tables(), reduce_spanned_responses(), span_request_queries(), span_series_request(), tidy_periods(), tidy_table_as_zoo()

Other blsR-utils: data_as_table(), data_as_tidy_table(), merge_tables(), merge_tidy_tables(), reduce_spanned_responses(), span_request_queries(), span_series_request(), tidy_periods(), tidy_table_as_zoo()

Other blsR-utils: data_as_table(), data_as_tidy_table(), merge_tables(), merge_tidy_tables(), reduce_spanned_responses(), span_request_queries(), span_series_request(), tidy_periods(), tidy_table_as_zoo()

Other blsR-utils: data_as_table(), data_as_tidy_table(), merge_tables(), merge_tidy_tables(), reduce_spanned_responses(), span_request_queries(), span_series_request(), tidy_periods(), tidy_table_as_zoo()

Examples


has_key <- bls_has_key()

if(has_key){
  original_key <- bls_get_key()
  bls_unset_key()
}

#no initial key
bls_has_key()

# Set a session key
bls_set_key("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

bls_has_key()

# Get session key
bls_get_key()

# Reset to original key
if(has_key) bls_set_key(original_key)

blsR documentation built on July 9, 2023, 5:29 p.m.