Skip to contents

Retrieves DNS records from Netlify for the specified domain using the getDnsRecords endpoint of Netlify's REST API.

Usage

netlify_dns_records_get(domain, token, max_tries = 3L)

Arguments

domain

Domain name to retrieve DNS records for. This is translated into the corresponding Netlify DNS Zone. A character scalar.

token

Personal access token used for authentication.

max_tries

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

Value

A tibble with the columns id, dns_zone_id, site_id, managed, type, hostname, value, ttl, priority, weight, port, flag, and tag.

See also

Examples

if (FALSE) {
yay::netlify_dns_records_get(domain = "my.site",
                             token = Sys.getenv("NETLIFY_PAT"))

# to write the "settable" record keys to a TOML file `dns_records.toml` with a `records` table
# NOTE that the CLI tool `jsontoml` is required for this: https://github.com/pelletier/go-toml/
yay::netlify_dns_records_get(domain = "my.site",
                             token = Sys.getenv("NETLIFY_PAT")) |>
  # remove records which can't be handled via API
  dplyr::filter(!managed) |>
  # remove Netlify-specific cols which aren't "settable"
  dplyr::select(
    any_of(yay:::netlify_dns_record_cols$key[yay:::netlify_dns_record_cols$settable])
  ) |>
  # convert to target list structure
  list(records = _) |>
  # convert to JSON
  jsonlite::toJSON(auto_unbox = TRUE,
                   pretty = TRUE) |>
  # convert JSON to TOML via external CLI
  system2(input = _,
          stdout = TRUE,
          command = "jsontoml") |>
  _[-1L] |>
  # write TOML to file
  brio::write_lines(path = "dns_records.toml")}