Skip to contents

Generate and perform request to an OpenFEC endpoint.

Usage

fec_call_api(
  path,
  query = list(),
  body = NULL,
  method = NULL,
  pagination = c("none", "basic"),
  max_results = Inf,
  max_reqs = Inf,
  api_key = Sys.getenv("FEC_API_KEY", unset = "DEMO_KEY"),
  call = rlang::caller_env()
)

Arguments

path

The route to an API endpoint. Optionally, a list or character vector with the path as one or more unnamed arguments (which will be concatenated with "/") plus named arguments to glue::glue() into the path.

query

An optional list or character vector of parameters to pass in the query portion of the request. Can also include a .multi argument to pass to httr2::req_url_query() to control how elements containing multiple values are handled.

body

An object to use as the body of the request. If any component of the body is a path, pass it through fs::path() or otherwise give it the class "fs_path" to indicate that it is a path.

method

If the method is something other than GET or POST, supply it. Case is ignored.

pagination

The pagination scheme to use. Currently either "none" (the default) or "basic" (a scheme that uses per_page and returned pages information). If an endpoint has a per_page argument, use "basic".

max_results

The maximum number of results to return. Note that slightly more results may be returned if max_results is not evenly divisible by 100.

max_reqs

The maximum number of separate requests to perform. Passed to the max_reqs argument of httr2::req_perform_iterative() when next_req is supplied. The default 2 should likely be changed to Inf after you validate the function.

api_key

An API key provided by the API provider. This key is not clearly documented in the API description. Check the API documentation for details.

call

The execution environment of a currently running function, e.g. caller_env(). The function will be mentioned in error messages as the source of the error. See the call argument of abort() for more information.

Value

A tibble with the results of the API call.