Skip to contents

Performs an API call to a NocoDB server and returns the response as a list if it is of type JSON, otherwise as a character scalar.

Usage

api(
  path,
  method = c("GET", "CONNECT", "DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT",
    "TRACE"),
  origin = pal::pkg_config_val("origin"),
  email = pal::pkg_config_val("email"),
  password = pal::pkg_config_val("password"),
  api_token = pal::pkg_config_val("api_token"),
  auth = TRUE,
  url_params = NULL,
  body_json = NULL,
  auto_unbox = TRUE,
  simplify = TRUE,
  flatten = TRUE,
  max_tries = 3L,
  verbosity = NULL
)

Arguments

path

character(1)
NocoDB API endpoint path.

method

character(1)
HTTP request method. One of "GET", "CONNECT", "DELETE", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" or "TRACE".

origin

character(1)
NocoDB server origin.

email

character(1)
E-mail address of the NocoDB user to authenticate with.

password

character(1)
Password of the NocoDB user to authenticate with.

api_token

character(1)
NocoDB API token. Takes precedence over email and password if provided.

auth

logical(1)
Whether or not to include an authentication header in the HTTP request.

url_params

list()
URL parameters added to the query string. Either NULL to omit or a named list of key-value pairs that define query parameters. Values must be scalars. To opt out of automatic conversion of non-character values to JSON strings or percent-encoding values, wrap values in I().

body_json

list()
Data to include as JSON in the HTTP request body. NULL means an empty body.

auto_unbox

logical(1)
Whether or not to automatically "unbox" length-1 vectors in body_json to JSON scalars.

simplify

logical(1)
Whether or not to automatically simplify JSON structures in the returned JSON. Enables/disables all simplify* arguments of jsonlite::fromJSON().

flatten

logical(1)
Whether or not to automatically flatten nested data frames in the returned JSON into a single non-nested data frame.

max_tries

integer(1)
Maximum number of attempts to retry in case of an HTTP error.

verbosity

How much information to print? This is a wrapper around req_verbose() that uses an integer to control verbosity:

  • 0: no output

  • 1: show headers

  • 2: show headers and bodies

  • 3: show headers, bodies, and curl status messages.

Use with_verbosity() to control the verbosity of requests that you can't affect directly.

Value

  • NULL if the API response's body is empty.

  • The API response's body as a list if it is of type JSON.

  • The API response's body as a character scalar in all other cases.

Details

See req_auth() for details about the authentication logic enabled via auth.

For full control over the performed HTTP request, resort to the lower-level req_basic().

See also

Other common functions: req_auth(), req_basic()