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"),
  hostname = pal::pkg_config_val("hostname"),
  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

NocoDB API endpoint path. A character scalar.

method

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

hostname

NocoDB server hostname. A character scalar.

email

E-mail address of the NocoDB user to authenticate with.

password

Password of the NocoDB user to authenticate with.

api_token

NocoDB API token. Takes precedence over email and password if provided.

auth

Whether or not to include an authentication header in the HTTP request.

url_params

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 a scalars, to opt out of escaping, wrap strings in I().

body_json

Data to include as JSON in the HTTP request body. Either a list or NULL for an empty body.

auto_unbox

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

simplify

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

flatten

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

max_tries

Maximum number of attempts to retry in case of an HTTP error. An integerish scalar.

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()