Package 'cloudflarer'

Title: Interface to the 'Cloudflare' API
Description: An 'R' interface to the 'Cloudflare' REST API (<https://developers.cloudflare.com/api/>). Wraps the v4 API with authenticated requests, response unwrapping, paginated list helpers, and a generic request function so users can call any endpoint that is not yet covered by a dedicated wrapper.
Authors: Athanasia Mo Mowinckel [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-5756-0223>, GitHub: drmowinckels)
Maintainer: Athanasia Mo Mowinckel <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9000
Built: 2026-07-09 14:31:44 UTC
Source: https://github.com/drmowinckels/cloudflarer

Help Index


Cloudflare Global API Key (legacy auth)

Description

Reads the Global API Key used together with cf_email() for Cloudflare's legacy authentication scheme. Prefer creating a scoped API token instead; see cf_token().

Usage

cf_api_key(api_key = NULL)

Arguments

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A character scalar with the API key.

See Also

Other authentication: cf_auth_mode(), cf_email(), cf_has_auth(), cf_sitrep(), cf_token(), cf_verify()

Examples

withr::with_envvar(
  c(CLOUDFLARE_API_KEY = "cloudflarer-example-key"),
  cf_api_key()
)

Detect which Cloudflare auth mode is configured

Description

Returns the credential type that the next request would use, based on the current environment:

Usage

cf_auth_mode()

Details

  • "token"CLOUDFLARE_API_TOKEN is set.

  • "key" – both CLOUDFLARE_EMAIL and CLOUDFLARE_API_KEY are set.

  • NA_character_ – no usable credentials are available.

When both are configured, the API token wins because it is the modern, scoped credential type.

Value

A character scalar ("token", "key", or NA_character_).

See Also

Other authentication: cf_api_key(), cf_email(), cf_has_auth(), cf_sitrep(), cf_token(), cf_verify()

Examples

cf_auth_mode()

Daily cache hit ratio for a zone

Description

Wraps the same GraphQL httpRequests1dGroups node as cf_zone_requests() but exposes the cache-specific fields: total requests/bytes, cached requests/bytes, and the derived cache hit ratios.

Usage

cf_cache_ratio(
  zone_id,
  since,
  until,
  limit = 100L,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier (zoneTag in GraphQL).

since, until

Date or POSIXct. Half-open ⁠[since, until)⁠.

limit

Maximum number of rows. Cloudflare caps the underlying query at 10000.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame with columns date (chr), requests, cached_requests, bytes, cached_bytes, request_hit_ratio, bandwidth_hit_ratio.

See Also

Other analytics: cf_dns_queries(), cf_firewall_events_by_day(), cf_firewall_events_top(), cf_get_rum_site(), cf_graphql(), cf_list_rum_sites(), cf_rum_page_views(), cf_rum_top(), cf_workers_invocations(), cf_zone_overview(), cf_zone_requests()

Examples

cf_cache_ratio(
  "abc123",
  since = Sys.Date() - 7,
  until = Sys.Date()
)

Collect every page of a paginated endpoint

Description

Given a request built with cf_request() (optionally with query filters piped on), walks every page of a Cloudflare list endpoint and concatenates the result arrays into a single list. Page size and paging cursor are added as query parameters on each request.

Usage

cf_collect(req, per_page = 50, max_pages = Inf, progress = FALSE, ...)

Arguments

req

An httr2_request from cf_request().

per_page

Integer page size. Cloudflare caps most endpoints at 50; some allow up to 1000.

max_pages

Optional integer. Stop after collecting this many pages. Useful for exploratory calls against large accounts. Inf (the default) collects everything.

progress

Whether to show a progress bar while paging.

...

Additional arguments passed to httr2::req_perform_iterative().

Value

A list of records.

See Also

Other requests: cf_request(), cf_resp()

Examples

cf_request("zones") |> cf_collect(per_page = 50)

Create a custom hostname

Description

Registers a customer hostname with SSL-for-SaaS.

Usage

cf_create_custom_hostname(
  zone_id,
  hostname,
  ssl_method = "txt",
  ssl_type = "dv",
  ssl = NULL,
  custom_metadata = NULL,
  custom_origin_server = NULL,
  ...,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

hostname

Customer-facing hostname (e.g. "shop.customer.com").

ssl_method

Domain Control Validation method: "http", "txt", or "email".

ssl_type

Certificate type, typically "dv".

ssl

Optional named list overriding the default SSL config. When supplied, takes precedence over ssl_method / ssl_type.

custom_metadata

Optional named list of metadata stored with the hostname.

custom_origin_server

Optional custom origin server (overrides zone fallback).

...

Additional fields forwarded to the API.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the created custom hostname.

See Also

Other ssl: cf_delete_custom_hostname(), cf_get_certificate_pack(), cf_get_custom_hostname(), cf_list_certificate_packs(), cf_list_custom_hostnames()

Examples

## Not run: 
cf_create_custom_hostname(
  "zone-1",
  hostname   = "shop.customer.com",
  ssl_method = "txt"
)

## End(Not run)

Create a D1 database

Description

Create a D1 database

Usage

cf_create_d1_database(
  account_id,
  name,
  primary_location_hint = NULL,
  ...,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

name

Database name. Must be unique within the account.

primary_location_hint

Optional Cloudflare region hint ("WNAM", "ENAM", "WEUR", "EEUR", "APAC", "OC").

...

Additional fields forwarded to the API.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the created database.

See Also

Other d1: cf_d1_query(), cf_delete_d1_database(), cf_get_d1_database(), cf_list_d1_databases()

Examples

## Not run: 
cf_create_d1_database("acc-1", name = "users")

## End(Not run)

Create a DNS record

Description

Create a DNS record

Usage

cf_create_dns_record(
  zone_id,
  type,
  name,
  content,
  ttl = 1,
  proxied = NULL,
  priority = NULL,
  comment = NULL,
  ...,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

type

Record type: "A", "AAAA", "CNAME", "MX", "TXT", "SRV", etc.

name

Record name (host). For the apex, pass "@" or the zone name.

content

Record content. For A/AAAA an IP address; for CNAME a hostname; for TXT the string value.

ttl

Time to live in seconds. 1 means "automatic" (Cloudflare's default).

proxied

Logical. Whether the record is proxied through Cloudflare. Applies to A/AAAA/CNAME.

priority

Integer. Required for MX records.

comment

Optional human-readable comment.

...

Additional fields forwarded to the API for record types with extra requirements (data for SRV, etc.).

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the created record.

See Also

Other dns: cf_delete_dns_record(), cf_get_dns_record(), cf_list_dns_records(), cf_update_dns_record()

Examples

cf_create_dns_record(
  "zone-1",
  type    = "A",
  name    = "www",
  content = "192.0.2.1",
  proxied = TRUE
)

Create a healthcheck

Description

Create a healthcheck

Usage

cf_create_healthcheck(
  zone_id,
  name,
  address,
  type = "HTTPS",
  check_regions = NULL,
  http_config = NULL,
  tcp_config = NULL,
  interval = 60,
  retries = 2,
  timeout = 5,
  description = NULL,
  suspended = NULL,
  ...,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

name

Display name for the healthcheck.

address

Hostname or IPv4/IPv6 address to monitor.

type

One of "HTTPS", "HTTP", or "TCP".

check_regions

Optional character vector of Cloudflare region codes ("WEU", "ENAM", etc.). When NULL, the API runs the check from all available regions.

http_config

Optional named list with HTTP/HTTPS-specific fields (path, port, method, expected_codes, expected_body, follow_redirects, allow_insecure, header).

tcp_config

Optional named list with TCP-specific fields (port, method).

interval

Polling interval in seconds.

retries

Number of retries before marking unhealthy.

timeout

Timeout per check, in seconds.

description

Optional human-readable description.

suspended

Logical. When TRUE, the check is paused.

...

Additional fields forwarded to the API.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the created healthcheck.

See Also

Other healthchecks: cf_delete_healthcheck(), cf_get_healthcheck(), cf_list_healthchecks(), cf_update_healthcheck()

Examples

## Not run: 
cf_create_healthcheck(
  "zone-1",
  name    = "api-prod",
  address = "api.example.com",
  type    = "HTTPS",
  http_config = list(path = "/health", expected_codes = "200")
)

## End(Not run)

Create a Workers KV namespace

Description

Create a Workers KV namespace

Usage

cf_create_kv_namespace(
  account_id,
  title,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

title

Character. Human-readable namespace name.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the created namespace.

See Also

Other workers: cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_create_kv_namespace("abc123", "sessions")

Create a Page Rule

Description

Each rule applies a list of actions whenever a request matches one of targets. The most common pattern: a single URL-match target plus one cache-related action (for example cache_level = "cache_everything" to bump a static site's hit ratio).

Usage

cf_create_page_rule(
  zone_id,
  targets,
  actions,
  priority = 1L,
  status = c("active", "disabled"),
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

targets

A list of target specifications. The simplest form is a single URL-match created by cf_page_rule_target(); see the example below.

actions

A list of action specifications. The simplest form is a list created by cf_page_rule_action().

priority

Integer. Higher number = applied first.

status

"active" or "disabled".

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the created rule.

See Also

Other zones: cf_delete_page_rule(), cf_get_page_rule(), cf_get_zone(), cf_get_zone_setting(), cf_get_zone_settings(), cf_list_firewall_rules(), cf_list_page_rules(), cf_list_zones(), cf_page_rule_action(), cf_page_rule_target(), cf_update_page_rule()

Examples

cf_create_page_rule(
  "abc123",
  targets = list(
    cf_page_rule_target("*example.com/blog/*")
  ),
  actions = list(
    cf_page_rule_action("cache_level", "cache_everything"),
    cf_page_rule_action("edge_cache_ttl", 7200)
  )
)

Create a Turnstile widget

Description

Create a Turnstile widget

Usage

cf_create_turnstile_widget(
  account_id,
  name,
  domains,
  mode = c("managed", "non-interactive", "invisible"),
  bot_fight_mode = FALSE,
  region = "world",
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

name

Character. Human-readable widget name.

domains

Character vector of domains where the widget will be embedded.

mode

Character. Visibility mode: "managed" (Cloudflare decides), "non-interactive" (no user interaction), or "invisible".

bot_fight_mode

Logical. Enable Bot Fight Mode integration.

region

Character. Where Turnstile runs from. "world" (default) or "china".

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with the created widget, including its sitekey and secret (only shown once).

See Also

Other turnstile: cf_delete_turnstile_widget(), cf_get_turnstile_widget(), cf_list_turnstile_widgets()

Examples

cf_create_turnstile_widget(
  "abc123",
  name = "comment-form",
  domains = c("example.com", "www.example.com"),
  mode = "managed"
)

Run a SQL query against a D1 database

Description

Executes one or more SQL statements against the database. Use params for parameterised queries to avoid string-interpolation issues.

Usage

cf_d1_query(
  account_id,
  database_id,
  sql,
  params = NULL,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

database_id

Character. D1 database uuid.

sql

Character. SQL statement(s) to execute.

params

Optional character vector of positional parameters bound to the ⁠?⁠ placeholders in sql.

as_df

Logical. When TRUE (the default), returns the first result set as a data.frame via cf_records_to_df(). Set to FALSE to get the full raw response (useful for multi-statement queries or when you need the metadata).

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of result rows when as_df = TRUE, otherwise the raw response (a list of result blocks, each with success, meta, and results).

See Also

Other d1: cf_create_d1_database(), cf_delete_d1_database(), cf_get_d1_database(), cf_list_d1_databases()

Examples

## Not run: 
cf_d1_query("acc-1", "db-1", "SELECT * FROM users WHERE id = ?", params = "42")

## End(Not run)

Delete a custom hostname

Description

Delete a custom hostname

Usage

cf_delete_custom_hostname(
  zone_id,
  custom_hostname_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

custom_hostname_id

Character. Custom hostname identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with the deleted hostname's id.

See Also

Other ssl: cf_create_custom_hostname(), cf_get_certificate_pack(), cf_get_custom_hostname(), cf_list_certificate_packs(), cf_list_custom_hostnames()

Examples

## Not run: 
cf_delete_custom_hostname("zone-1", "ch-1")

## End(Not run)

Delete a D1 database

Description

Delete a D1 database

Usage

cf_delete_d1_database(
  account_id,
  database_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

database_id

Character. D1 database uuid.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with the API response.

See Also

Other d1: cf_create_d1_database(), cf_d1_query(), cf_get_d1_database(), cf_list_d1_databases()

Examples

## Not run: 
cf_delete_d1_database("acc-1", "db-1")

## End(Not run)

Delete a DNS record

Description

Delete a DNS record

Usage

cf_delete_dns_record(
  zone_id,
  record_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

record_id

Character. DNS record identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with the deleted record's id.

See Also

Other dns: cf_create_dns_record(), cf_get_dns_record(), cf_list_dns_records(), cf_update_dns_record()

Examples

cf_delete_dns_record("zone-1", "rec-1")

Delete a healthcheck

Description

Delete a healthcheck

Usage

cf_delete_healthcheck(
  zone_id,
  healthcheck_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

healthcheck_id

Character. Healthcheck identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with the deleted healthcheck's id.

See Also

Other healthchecks: cf_create_healthcheck(), cf_get_healthcheck(), cf_list_healthchecks(), cf_update_healthcheck()

Examples

## Not run: 
cf_delete_healthcheck("zone-1", "hc-1")

## End(Not run)

Delete a Workers KV namespace

Description

Delete a Workers KV namespace

Usage

cf_delete_kv_namespace(
  account_id,
  namespace_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

namespace_id

Character. KV namespace identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

NULL, invisibly. Cloudflare returns an empty result on success.

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_delete_kv_namespace("abc123", "ns-1")

Delete a value from a Workers KV namespace

Description

Delete a value from a Workers KV namespace

Usage

cf_delete_kv_value(
  account_id,
  namespace_id,
  key_name,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

namespace_id

Character. KV namespace identifier.

key_name

Character. Key to read.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

NULL, invisibly. Cloudflare returns an empty result on success.

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_delete_kv_value("abc123", "ns-1", "greeting")

Delete multiple keys from a Workers KV namespace

Description

Delete multiple keys from a Workers KV namespace

Usage

cf_delete_kv_values(
  account_id,
  namespace_id,
  keys,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

namespace_id

Character. KV namespace identifier.

keys

Character vector of key names to delete. Up to 10,000 keys per call.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with successful_key_count and unsuccessful_keys.

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_delete_kv_values("abc123", "ns-1", c("greeting", "farewell"))

Delete a Page Rule

Description

Delete a Page Rule

Usage

cf_delete_page_rule(
  zone_id,
  rule_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

rule_id

Character. Page Rule identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with the deleted rule's id.

See Also

Other zones: cf_create_page_rule(), cf_get_page_rule(), cf_get_zone(), cf_get_zone_setting(), cf_get_zone_settings(), cf_list_firewall_rules(), cf_list_page_rules(), cf_list_zones(), cf_page_rule_action(), cf_page_rule_target(), cf_update_page_rule()

Examples

cf_delete_page_rule("abc123", "rule-1")

Delete a Turnstile widget

Description

Delete a Turnstile widget

Usage

cf_delete_turnstile_widget(
  account_id,
  sitekey,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

sitekey

Character. Widget sitekey.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with the deleted widget's sitekey.

See Also

Other turnstile: cf_create_turnstile_widget(), cf_get_turnstile_widget(), cf_list_turnstile_widgets()

Examples

cf_delete_turnstile_widget("abc123", "0x4AAA...")

Daily DNS query counts for a zone

Description

Wraps the Cloudflare GraphQL dnsAnalyticsAdaptiveGroups node, grouped by day. Returns a tidy data.frame.

Usage

cf_dns_queries(
  zone_id,
  since,
  until,
  limit = 100L,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier (zoneTag in GraphQL).

since, until

Date or POSIXct. Half-open ⁠[since, until)⁠.

limit

Maximum number of rows. Cloudflare caps the underlying query at 10000.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Details

Requires an API token with the ⁠Account Analytics: Read⁠ (or ⁠Zone Analytics: Read⁠) permission. The legacy Global API Key has full access.

Value

A data.frame with columns date (chr) and queries (int).

See Also

Other analytics: cf_cache_ratio(), cf_firewall_events_by_day(), cf_firewall_events_top(), cf_get_rum_site(), cf_graphql(), cf_list_rum_sites(), cf_rum_page_views(), cf_rum_top(), cf_workers_invocations(), cf_zone_overview(), cf_zone_requests()

Examples

cf_dns_queries(
  "abc123",
  since = Sys.Date() - 7,
  until = Sys.Date()
)

Cloudflare account email (legacy auth)

Description

Reads the account email used together with cf_api_key() for Cloudflare's legacy Global API Key authentication. Defaults to Sys.getenv("CLOUDFLARE_EMAIL").

Usage

cf_email(email = NULL)

Arguments

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

Value

A character scalar with the email address.

See Also

Other authentication: cf_api_key(), cf_auth_mode(), cf_has_auth(), cf_sitrep(), cf_token(), cf_verify()

Examples

withr::with_envvar(
  c(CLOUDFLARE_EMAIL = "[email protected]"),
  cf_email()
)

Daily firewall event counts for a zone

Description

Wraps the Cloudflare GraphQL firewallEventsAdaptiveGroups node, grouped by day. Returns a tidy data.frame with one row per day.

Usage

cf_firewall_events_by_day(
  zone_id,
  since,
  until,
  limit = 100L,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier (zoneTag in GraphQL).

since, until

Date or POSIXct. Half-open ⁠[since, until)⁠.

limit

Maximum number of rows. Cloudflare caps the underlying query at 10000.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Details

Requires:

  • A Cloudflare Pro, Business, or Enterprise plan – the underlying GraphQL node is not available on the Free plan.

  • An API token with ⁠Account Analytics: Read⁠ (or ⁠Zone Analytics: Read⁠) permission, or the legacy Global API Key.

Either condition unmet produces a ⁠zone ... does not have access to the path⁠ error.

Value

A data.frame with columns date (chr) and events (int).

See Also

Other analytics: cf_cache_ratio(), cf_dns_queries(), cf_firewall_events_top(), cf_get_rum_site(), cf_graphql(), cf_list_rum_sites(), cf_rum_page_views(), cf_rum_top(), cf_workers_invocations(), cf_zone_overview(), cf_zone_requests()

Examples

cf_firewall_events_by_day(
  "abc123",
  since = Sys.Date() - 30,
  until = Sys.Date()
)

Top firewall events for a zone by a chosen dimension

Description

Groups firewallEventsAdaptiveGroups by a single dimension and returns the top entries by count.

Usage

cf_firewall_events_top(
  zone_id,
  since,
  until,
  dimension = "action",
  limit = 25L,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier (zoneTag in GraphQL).

since, until

Date or POSIXct. Half-open ⁠[since, until)⁠.

dimension

Character. Dimension name to group by. Common choices: "action" (block, challenge, ...), "source" (WAF, firewall rules, security level, ...), "ruleId", "clientCountryName", "clientRequestPath", "clientRequestHTTPHost", "userAgent". Must be a single field name (letters, digits, underscores; not starting with a digit) and cannot be "events", which names the metric column.

limit

Number of rows to return.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame with two columns: the requested dimension and events (the event count).

See Also

Other analytics: cf_cache_ratio(), cf_dns_queries(), cf_firewall_events_by_day(), cf_get_rum_site(), cf_graphql(), cf_list_rum_sites(), cf_rum_page_views(), cf_rum_top(), cf_workers_invocations(), cf_zone_overview(), cf_zone_requests()

Examples

cf_firewall_events_top(
  "abc123",
  since = Sys.Date() - 7,
  until = Sys.Date(),
  dimension = "action",
  limit = 10
)

Get a single account

Description

Get a single account

Usage

cf_get_account(account_id, token = NULL, email = NULL, api_key = NULL)

Arguments

account_id

Character. Cloudflare account identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the account.

See Also

Other accounts: cf_list_accounts()

Examples

cf_get_account("abc123")

Get a single account Ruleset (with its rules)

Description

Get a single account Ruleset (with its rules)

Usage

cf_get_account_ruleset(
  account_id,
  ruleset_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

ruleset_id

Character. Ruleset identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the ruleset; its rules element is itself a list of rule objects.

See Also

Other rulesets: cf_get_ruleset(), cf_list_account_rulesets(), cf_list_rulesets()

Examples

cf_get_account_ruleset("acc-1", "rs-1")

Get a single SSL certificate pack

Description

Get a single SSL certificate pack

Usage

cf_get_certificate_pack(
  zone_id,
  pack_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

pack_id

Character. Certificate pack identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the certificate pack.

See Also

Other ssl: cf_create_custom_hostname(), cf_delete_custom_hostname(), cf_get_custom_hostname(), cf_list_certificate_packs(), cf_list_custom_hostnames()

Examples

## Not run: 
cf_get_certificate_pack("zone-1", "pack-1")

## End(Not run)

Get a single custom hostname

Description

Get a single custom hostname

Usage

cf_get_custom_hostname(
  zone_id,
  custom_hostname_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

custom_hostname_id

Character. Custom hostname identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the custom hostname.

See Also

Other ssl: cf_create_custom_hostname(), cf_delete_custom_hostname(), cf_get_certificate_pack(), cf_list_certificate_packs(), cf_list_custom_hostnames()

Examples

## Not run: 
cf_get_custom_hostname("zone-1", "ch-1")

## End(Not run)

Get a single D1 database

Description

Get a single D1 database

Usage

cf_get_d1_database(
  account_id,
  database_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

database_id

Character. D1 database uuid.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the database.

See Also

Other d1: cf_create_d1_database(), cf_d1_query(), cf_delete_d1_database(), cf_list_d1_databases()

Examples

## Not run: 
cf_get_d1_database("acc-1", "db-1")

## End(Not run)

Get a single DNS record

Description

Get a single DNS record

Usage

cf_get_dns_record(
  zone_id,
  record_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

record_id

Character. DNS record identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the record.

See Also

Other dns: cf_create_dns_record(), cf_delete_dns_record(), cf_list_dns_records(), cf_update_dns_record()

Examples

cf_get_dns_record("zone-1", "rec-1")

Email Routing settings for a zone

Description

Returns the current Email Routing configuration for the zone: enabled/disabled, SPF/MX status, last-modified timestamps.

Usage

cf_get_email_routing_settings(
  zone_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with the routing settings.

See Also

Other email: cf_list_email_routing_addresses(), cf_list_email_routing_rules()

Examples

cf_get_email_routing_settings("abc123")

Get a single healthcheck

Description

Get a single healthcheck

Usage

cf_get_healthcheck(
  zone_id,
  healthcheck_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

healthcheck_id

Character. Healthcheck identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the healthcheck.

See Also

Other healthchecks: cf_create_healthcheck(), cf_delete_healthcheck(), cf_list_healthchecks(), cf_update_healthcheck()

Examples

## Not run: 
cf_get_healthcheck("zone-1", "hc-1")

## End(Not run)

Get a single Workers KV namespace

Description

Get a single Workers KV namespace

Usage

cf_get_kv_namespace(
  account_id,
  namespace_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

namespace_id

Character. KV namespace identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the namespace.

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_get_kv_namespace("abc123", "ns-1")

Read a value from a Workers KV namespace

Description

Unlike most Cloudflare endpoints, this one returns the raw stored value rather than a JSON envelope, so the result is not passed through cf_resp().

Usage

cf_get_kv_value(
  account_id,
  namespace_id,
  key_name,
  as = c("text", "raw"),
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

namespace_id

Character. KV namespace identifier.

key_name

Character. Key to read.

as

Character. "text" (the default) returns the value as a string via httr2::resp_body_string(); "raw" returns the raw bytes via httr2::resp_body_raw(), useful for binary values.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A character string, or a raw vector when as = "raw".

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_get_kv_value("abc123", "ns-1", "greeting")

Get a single Page Rule

Description

Get a single Page Rule

Usage

cf_get_page_rule(zone_id, rule_id, token = NULL, email = NULL, api_key = NULL)

Arguments

zone_id

Character. Cloudflare zone identifier.

rule_id

Character. Page Rule identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the rule, including its targets and actions.

See Also

Other zones: cf_create_page_rule(), cf_delete_page_rule(), cf_get_zone(), cf_get_zone_setting(), cf_get_zone_settings(), cf_list_firewall_rules(), cf_list_page_rules(), cf_list_zones(), cf_page_rule_action(), cf_page_rule_target(), cf_update_page_rule()

Examples

cf_get_page_rule("abc123", "rule-1")

Get a single Cloudflare Pages project

Description

Get a single Cloudflare Pages project

Usage

cf_get_pages_project(
  account_id,
  project_name,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

project_name

Character. Pages project name.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the project, including build config, domains, and the latest deployment.

See Also

Other pages: cf_list_pages_deployments(), cf_list_pages_projects()

Examples

cf_get_pages_project("abc123", "my-site")

Get a single R2 bucket

Description

Get a single R2 bucket

Usage

cf_get_r2_bucket(
  account_id,
  bucket_name,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

bucket_name

Character. R2 bucket name.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the bucket.

See Also

Other r2: cf_list_r2_buckets()

Examples

cf_get_r2_bucket("abc123", "my-bucket")

Get a single zone Ruleset (with its rules)

Description

Get a single zone Ruleset (with its rules)

Usage

cf_get_ruleset(zone_id, ruleset_id, token = NULL, email = NULL, api_key = NULL)

Arguments

zone_id

Character. Cloudflare zone identifier.

ruleset_id

Character. Ruleset identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the ruleset; its rules element is itself a list of rule objects.

See Also

Other rulesets: cf_get_account_ruleset(), cf_list_account_rulesets(), cf_list_rulesets()

Examples

cf_get_ruleset("abc123", "rs-1")

Get a single Web Analytics (RUM) site

Description

Get a single Web Analytics (RUM) site

Usage

cf_get_rum_site(
  account_id,
  site_tag,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

site_tag

Character. RUM site tag (sometimes called "site identifier").

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the site.

See Also

Other analytics: cf_cache_ratio(), cf_dns_queries(), cf_firewall_events_by_day(), cf_firewall_events_top(), cf_graphql(), cf_list_rum_sites(), cf_rum_page_views(), cf_rum_top(), cf_workers_invocations(), cf_zone_overview(), cf_zone_requests()

Examples

cf_get_rum_site("acc-1", "abc-tag")

Get a single Cloudflare Tunnel

Description

Get a single Cloudflare Tunnel

Usage

cf_get_tunnel(
  account_id,
  tunnel_id,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

tunnel_id

Character. Tunnel identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the tunnel.

See Also

Other tunnels: cf_list_tunnel_connections(), cf_list_tunnels()

Examples

cf_get_tunnel("abc123", "tunnel-1")

Get a single Turnstile widget

Description

Get a single Turnstile widget

Usage

cf_get_turnstile_widget(
  account_id,
  sitekey,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

sitekey

Character. Widget sitekey.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the widget.

See Also

Other turnstile: cf_create_turnstile_widget(), cf_delete_turnstile_widget(), cf_list_turnstile_widgets()

Examples

cf_get_turnstile_widget("abc123", "0x4AAA...")

Get metadata for a single Workers script

Description

Returns the script's metadata (placement, bindings, etc.). To fetch the actual source, use the API's ⁠/workers/scripts/{name}/content⁠ endpoint via cf_request().

Usage

cf_get_workers_script(
  account_id,
  script_name,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

script_name

Character. Worker script name.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with the script metadata.

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_get_workers_script("abc123", "my-worker")

Get a single zone

Description

Get a single zone

Usage

cf_get_zone(zone_id, token = NULL, email = NULL, api_key = NULL)

Arguments

zone_id

Character. Cloudflare zone identifier.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the zone.

See Also

Other zones: cf_create_page_rule(), cf_delete_page_rule(), cf_get_page_rule(), cf_get_zone_setting(), cf_get_zone_settings(), cf_list_firewall_rules(), cf_list_page_rules(), cf_list_zones(), cf_page_rule_action(), cf_page_rule_target(), cf_update_page_rule()

Examples

cf_get_zone("abc123")

Get a single zone setting

Description

Get a single zone setting

Usage

cf_get_zone_setting(
  zone_id,
  setting,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

setting

Character. Setting name (for example "ssl", "cache_level", "security_level").

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with the setting's id, value, modified_on, and editability flags.

See Also

Other zones: cf_create_page_rule(), cf_delete_page_rule(), cf_get_page_rule(), cf_get_zone(), cf_get_zone_settings(), cf_list_firewall_rules(), cf_list_page_rules(), cf_list_zones(), cf_page_rule_action(), cf_page_rule_target(), cf_update_page_rule()

Examples

cf_get_zone_setting("abc123", "ssl")

Get zone settings

Description

Returns the full settings catalogue for a zone (cache level, SSL mode, minify, security level, ...). One row per setting.

Usage

cf_get_zone_settings(
  zone_id,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of settings (or list when as_df = FALSE).

See Also

Other zones: cf_create_page_rule(), cf_delete_page_rule(), cf_get_page_rule(), cf_get_zone(), cf_get_zone_setting(), cf_list_firewall_rules(), cf_list_page_rules(), cf_list_zones(), cf_page_rule_action(), cf_page_rule_target(), cf_update_page_rule()

Examples

cf_get_zone_settings("abc123")

Run a Cloudflare GraphQL Analytics query

Description

Cloudflare's Analytics GraphQL API exposes most current and historical analytics datasets (HTTP requests, DNS, firewall, Workers, R2, etc.) behind a single endpoint: POST /graphql. The response shape is the standard GraphQL ⁠{data, errors}⁠ envelope, not Cloudflare's REST envelope, so this function is a separate path from cf_request().

Usage

cf_graphql(
  query,
  ...,
  .operation_name = NULL,
  .token = NULL,
  .email = NULL,
  .api_key = NULL,
  .envir = parent.frame()
)

Arguments

query

Character. A GraphQL query string.

...

Named GraphQL variables. For example cf_graphql(query, zoneTag = "abc", limit = 10).

.operation_name

Optional operation name when the query contains multiple operations.

.token, .email, .api_key

Optional per-call credentials. Dot-prefixed to avoid clashing with GraphQL variable names. See cf_token(), cf_email(), cf_api_key().

.envir

Environment for error reporting. Defaults to the caller, so error messages point at the user's code.

Details

Variables are passed through ... as named arguments, the same pattern used by the meetupr package. All values must be named; an unnamed value raises an error before the request is made.

Value

The parsed response body, including data and (when present) extensions. Any non-empty errors array raises a classed cloudflarer_error.

See Also

Other analytics: cf_cache_ratio(), cf_dns_queries(), cf_firewall_events_by_day(), cf_firewall_events_top(), cf_get_rum_site(), cf_list_rum_sites(), cf_rum_page_views(), cf_rum_top(), cf_workers_invocations(), cf_zone_overview(), cf_zone_requests()

Examples

res <- cf_graphql(
  "query Viewer($accountTag: String!) {
     viewer {
       accounts(filter: { accountTag: $accountTag }) {
         accountTag
       }
     }
   }",
  accountTag = "abc123"
)
res$data$viewer$accounts

res <- cf_graphql(
  "
  query ZoneRequests($zoneTag: String!, $since: Date!, $until: Date!) {
    viewer {
      zones(filter: { zoneTag: $zoneTag }) {
        httpRequests1dGroups(
          limit: 100,
          filter: { date_geq: $since, date_lt: $until }
        ) {
          dimensions { date }
          sum { requests bytes pageViews }
          uniq { uniques }
        }
      }
    }
  }
  ",
  zoneTag = "abc123",
  since = "2026-05-01",
  until = "2026-05-08"
)

Check whether any Cloudflare credentials are configured

Description

Returns TRUE when cf_auth_mode() returns a non-NA value. Useful in examples, vignettes, and conditional test code.

Usage

cf_has_auth()

Value

Logical scalar.

See Also

Other authentication: cf_api_key(), cf_auth_mode(), cf_email(), cf_sitrep(), cf_token(), cf_verify()

Examples

cf_has_auth()

List Rulesets for an account

Description

Returns the rulesets configured at the account level (typically the curated managed rulesets you can deploy with overrides).

Usage

cf_list_account_rulesets(
  account_id,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of rulesets (or list when as_df = FALSE).

See Also

Other rulesets: cf_get_account_ruleset(), cf_get_ruleset(), cf_list_rulesets()

Examples

cf_list_account_rulesets("acc-1")

List accounts

Description

Lists all accounts the authenticated user has access to.

Usage

cf_list_accounts(
  name = NULL,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

name

Optional name filter passed to the API.

per_page

Page size, see cf_collect().

max_pages

Maximum number of pages to retrieve, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE to get the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of account records (or a list when as_df = FALSE).

See Also

Other accounts: cf_get_account()

Examples

cf_list_accounts()

List SSL certificate packs in a zone

Description

Returns the SSL certificate packs (universal, advanced, custom) issued for the zone.

Usage

cf_list_certificate_packs(
  zone_id,
  status = NULL,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

status

Optional status filter, for example "active" or "pending_validation".

per_page, max_pages

Pagination controls, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df().

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of certificate pack records (or list when as_df = FALSE).

See Also

Other ssl: cf_create_custom_hostname(), cf_delete_custom_hostname(), cf_get_certificate_pack(), cf_get_custom_hostname(), cf_list_custom_hostnames()

Examples

## Not run: 
cf_list_certificate_packs("zone-1")
cf_list_certificate_packs("zone-1", status = "active")

## End(Not run)

List custom hostnames in a zone

Description

Returns the SSL-for-SaaS custom hostnames attached to the zone.

Usage

cf_list_custom_hostnames(
  zone_id,
  hostname = NULL,
  ssl = NULL,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

hostname

Optional hostname filter (substring match).

ssl

Optional SSL status filter (e.g. "active", "pending_validation").

per_page, max_pages

Pagination controls, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df().

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of custom hostname records (or list when as_df = FALSE).

See Also

Other ssl: cf_create_custom_hostname(), cf_delete_custom_hostname(), cf_get_certificate_pack(), cf_get_custom_hostname(), cf_list_certificate_packs()

Examples

## Not run: 
cf_list_custom_hostnames("zone-1")

## End(Not run)

List D1 databases in an account

Description

Returns the D1 (serverless SQL) databases for the account.

Usage

cf_list_d1_databases(
  account_id,
  name = NULL,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

name

Optional name filter (substring match).

per_page, max_pages

Pagination controls, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df().

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of D1 database records (or list when as_df = FALSE).

See Also

Other d1: cf_create_d1_database(), cf_d1_query(), cf_delete_d1_database(), cf_get_d1_database()

Examples

## Not run: 
cf_list_d1_databases("acc-1")

## End(Not run)

List DNS records in a zone

Description

List DNS records in a zone

Usage

cf_list_dns_records(
  zone_id,
  type = NULL,
  name = NULL,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

type

Optional record type filter, for example "A" or "CNAME".

name

Optional record name filter.

per_page

Page size, see cf_collect().

max_pages

Maximum pages to retrieve, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of DNS records (or list when as_df = FALSE).

See Also

Other dns: cf_create_dns_record(), cf_delete_dns_record(), cf_get_dns_record(), cf_update_dns_record()

Examples

cf_list_dns_records("abc123")
cf_list_dns_records("abc123", type = "A")

List Email Routing destination addresses

Description

Returns the verified destination addresses available for routing in the account. Destinations are account-scoped, not zone-scoped, because the same destination can be used across multiple routed zones.

Usage

cf_list_email_routing_addresses(
  account_id,
  verified_only = FALSE,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

verified_only

Logical. When TRUE, asks the API to return only verified addresses.

per_page, max_pages

Pagination controls.

as_df

Logical. See cf_list_email_routing_rules().

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of destination addresses (or list when as_df = FALSE).

See Also

Other email: cf_get_email_routing_settings(), cf_list_email_routing_rules()

Examples

cf_list_email_routing_addresses("abc123")

List Email Routing rules for a zone

Description

Returns the address-matching rules that decide how incoming emails are forwarded.

Usage

cf_list_email_routing_rules(
  zone_id,
  enabled_only = FALSE,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

enabled_only

Logical. When TRUE, asks the API to return only enabled rules.

per_page, max_pages

Pagination controls, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df().

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of routing rules (or list when as_df = FALSE).

See Also

Other email: cf_get_email_routing_settings(), cf_list_email_routing_addresses()

Examples

cf_list_email_routing_rules("abc123")

List firewall rules for a zone

Description

Returns the firewall rules (expression-based custom rules) configured for the zone. This is the classic firewall-rules endpoint; for the newer Rulesets API use cf_request() against ⁠/zones/{id}/rulesets⁠.

Usage

cf_list_firewall_rules(
  zone_id,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

per_page, max_pages

Pagination controls, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of firewall rules (or list when as_df = FALSE). Each rule's filter nested object becomes a list-column.

See Also

Other zones: cf_create_page_rule(), cf_delete_page_rule(), cf_get_page_rule(), cf_get_zone(), cf_get_zone_setting(), cf_get_zone_settings(), cf_list_page_rules(), cf_list_zones(), cf_page_rule_action(), cf_page_rule_target(), cf_update_page_rule()

Examples

cf_list_firewall_rules("abc123")

List standalone healthchecks in a zone

Description

Returns the standalone Healthchecks configured in the zone. These are separate from load-balancer pool monitors.

Usage

cf_list_healthchecks(
  zone_id,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

per_page, max_pages

Pagination controls, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df().

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of healthcheck records (or list when as_df = FALSE).

See Also

Other healthchecks: cf_create_healthcheck(), cf_delete_healthcheck(), cf_get_healthcheck(), cf_update_healthcheck()

Examples

## Not run: 
cf_list_healthchecks("zone-1")

## End(Not run)

List the keys in a Workers KV namespace

Description

Walks the namespace's cursor-paginated keys endpoint and concatenates every page into a single result. Unlike the offset-paginated list endpoints wrapped by cf_collect(), Cloudflare paginates KV keys with an opaque cursor, so this wrapper keeps its own loop instead.

Usage

cf_list_kv_keys(
  account_id,
  namespace_id,
  prefix = NULL,
  limit = 1000,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

namespace_id

Character. KV namespace identifier.

prefix

Optional character. Restrict results to keys starting with this prefix.

limit

Integer. Page size, between 10 and 1000.

max_pages

Optional integer. Stop after collecting this many pages. Inf (the default) collects every key.

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of key records (or list when as_df = FALSE), each with name, expiration, and metadata (when set).

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_list_kv_keys("abc123", "ns-1")

List Workers KV namespaces

Description

Returns the KV namespaces in the supplied account.

Usage

cf_list_kv_namespaces(
  account_id,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

per_page, max_pages

Pagination controls, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of KV namespace records (or list when as_df = FALSE).

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_list_kv_namespaces("abc123")

List Page Rules for a zone

Description

Returns the Page Rules configured for a zone (URL-pattern based overrides for cache, SSL, security, redirects, etc.).

Usage

cf_list_page_rules(
  zone_id,
  status = NULL,
  order = NULL,
  direction = NULL,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

status

Optional status filter ("active" or "disabled").

order

Optional ordering, see the Cloudflare API reference. For example "priority" or "status".

direction

Optional sort direction, "asc" or "desc".

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of page rules (or list when as_df = FALSE). Each rule's targets and actions are kept as list-columns because they are themselves arrays of nested objects.

See Also

Other zones: cf_create_page_rule(), cf_delete_page_rule(), cf_get_page_rule(), cf_get_zone(), cf_get_zone_setting(), cf_get_zone_settings(), cf_list_firewall_rules(), cf_list_zones(), cf_page_rule_action(), cf_page_rule_target(), cf_update_page_rule()

Examples

cf_list_page_rules("abc123")

List deployments for a Pages project

Description

Returns the recent deployments (build history) for a Pages project, ordered by date descending.

Usage

cf_list_pages_deployments(
  account_id,
  project_name,
  per_page = 25,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

project_name

Character. Pages project name.

per_page, max_pages

Pagination controls.

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df().

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of deployment records (or list when as_df = FALSE).

See Also

Other pages: cf_get_pages_project(), cf_list_pages_projects()

Examples

cf_list_pages_deployments("abc123", "my-site")

List Cloudflare Pages projects

Description

Returns the Pages projects in the supplied account. The Pages projects endpoint does not accept pagination parameters (unlike most other Cloudflare list endpoints) and returns every project in a single call.

Usage

cf_list_pages_projects(
  account_id,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of Pages projects (or list when as_df = FALSE).

See Also

Other pages: cf_get_pages_project(), cf_list_pages_deployments()

Examples

cf_list_pages_projects("abc123")

List R2 buckets in an account

Description

Returns the R2 object-storage buckets in the supplied account.

Usage

cf_list_r2_buckets(
  account_id,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of bucket records (or list when as_df = FALSE).

See Also

Other r2: cf_get_r2_bucket()

Examples

cf_list_r2_buckets("abc123")

List Rulesets for a zone

Description

Returns the rulesets configured at the zone level. The Rulesets API is Cloudflare's modern, unified surface for firewall rules, request transforms, cache rules, rate limits, redirects, and more.

Usage

cf_list_rulesets(
  zone_id,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of rulesets (or list when as_df = FALSE).

See Also

Other rulesets: cf_get_account_ruleset(), cf_get_ruleset(), cf_list_account_rulesets()

Examples

cf_list_rulesets("abc123")

List Web Analytics (RUM) sites

Description

Lists sites configured with the Cloudflare Web Analytics beacon in the supplied account. Web Analytics works on any site that includes the beacon snippet, whether or not the site is proxied through Cloudflare.

Usage

cf_list_rum_sites(
  account_id,
  order_by = NULL,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

order_by

Optional column name to sort by, for example "created" or "host".

per_page, max_pages

Pagination controls, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE to get the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of site records (or list when as_df = FALSE).

See Also

Other analytics: cf_cache_ratio(), cf_dns_queries(), cf_firewall_events_by_day(), cf_firewall_events_top(), cf_get_rum_site(), cf_graphql(), cf_rum_page_views(), cf_rum_top(), cf_workers_invocations(), cf_zone_overview(), cf_zone_requests()

Examples

cf_list_rum_sites("acc-1")

List active connections for a Cloudflare Tunnel

Description

Returns the currently-connected cloudflared instances for the tunnel.

Usage

cf_list_tunnel_connections(
  account_id,
  tunnel_id,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

tunnel_id

Character. Tunnel identifier.

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df().

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of connection records (or list when as_df = FALSE).

See Also

Other tunnels: cf_get_tunnel(), cf_list_tunnels()

Examples

cf_list_tunnel_connections("abc123", "tunnel-1")

List Cloudflare Tunnels

Description

Returns the cloudflared tunnels (Zero Trust) configured in the supplied account.

Usage

cf_list_tunnels(
  account_id,
  is_deleted = FALSE,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

is_deleted

Logical. When TRUE, include deleted tunnels.

per_page, max_pages

Pagination controls, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df().

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of tunnel records (or list when as_df = FALSE).

See Also

Other tunnels: cf_get_tunnel(), cf_list_tunnel_connections()

Examples

cf_list_tunnels("abc123")

List Turnstile widgets

Description

Lists the Turnstile (Cloudflare's CAPTCHA replacement) widgets configured in an account.

Usage

cf_list_turnstile_widgets(
  account_id,
  per_page = 25,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

per_page, max_pages

Pagination controls, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of widget records (or list when as_df = FALSE).

See Also

Other turnstile: cf_create_turnstile_widget(), cf_delete_turnstile_widget(), cf_get_turnstile_widget()

Examples

cf_list_turnstile_widgets("abc123")

List Workers scripts in an account

Description

Returns the Workers scripts deployed in the supplied account.

Usage

cf_list_workers_scripts(
  account_id,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of Workers script records (or list when as_df = FALSE).

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_list_workers_scripts("abc123")

List zones

Description

Lists the zones (domains) accessible to the authenticated credential.

Usage

cf_list_zones(
  name = NULL,
  status = NULL,
  account_id = NULL,
  per_page = 50,
  max_pages = Inf,
  as_df = TRUE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

name

Optional zone name to filter by.

status

Optional status filter (for example "active").

account_id

Optional account identifier to scope the listing.

per_page

Page size, see cf_collect().

max_pages

Maximum pages to retrieve, see cf_collect().

as_df

Logical. When TRUE (the default), returns a data.frame via cf_records_to_df(). Set to FALSE for the raw nested list.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame of zone records (or a list when as_df = FALSE).

See Also

Other zones: cf_create_page_rule(), cf_delete_page_rule(), cf_get_page_rule(), cf_get_zone(), cf_get_zone_setting(), cf_get_zone_settings(), cf_list_firewall_rules(), cf_list_page_rules(), cf_page_rule_action(), cf_page_rule_target(), cf_update_page_rule()

Examples

cf_list_zones()
cf_list_zones(name = "example.com")

Build a Page Rule action

Description

Produces the nested list that the Cloudflare API expects for a single Page Rule action. Use it inside an actions = list(...) argument to cf_create_page_rule() or cf_update_page_rule().

Usage

cf_page_rule_action(id, value)

Arguments

id

Character. The action name (Cloudflare's "setting" identifier).

value

The value to set. For most actions this is a character or integer scalar; some (for example "forwarding_url") expect a nested list.

Details

Common id values: "cache_level", "edge_cache_ttl", "browser_cache_ttl", "always_use_https", "security_level", "ssl", "forwarding_url".

Value

A named list ready to splice into actions.

See Also

Other zones: cf_create_page_rule(), cf_delete_page_rule(), cf_get_page_rule(), cf_get_zone(), cf_get_zone_setting(), cf_get_zone_settings(), cf_list_firewall_rules(), cf_list_page_rules(), cf_list_zones(), cf_page_rule_target(), cf_update_page_rule()

Examples

cf_page_rule_action("cache_level", "cache_everything")
cf_page_rule_action("edge_cache_ttl", 7200)
cf_page_rule_action(
  "forwarding_url",
  list(url = "https://example.com/$1", status_code = 301)
)

Build a Page Rule URL-match target

Description

Produces the nested list that the Cloudflare API expects for the most common Page Rule target: a URL pattern with matches semantics (asterisks act as wildcards). Use it inside a targets = list(...) argument to cf_create_page_rule().

Usage

cf_page_rule_target(url_pattern)

Arguments

url_pattern

Character. The URL pattern, for example "*example.com/blog/*".

Value

A named list ready to splice into targets.

See Also

Other zones: cf_create_page_rule(), cf_delete_page_rule(), cf_get_page_rule(), cf_get_zone(), cf_get_zone_setting(), cf_get_zone_settings(), cf_list_firewall_rules(), cf_list_page_rules(), cf_list_zones(), cf_page_rule_action(), cf_update_page_rule()

Examples

cf_page_rule_target("*example.com/blog/*")

Purge zone cache

Description

Tells Cloudflare to drop cached content for a zone. Pass one of the targeted-purge arguments to scope the purge, or set purge_everything = TRUE to wipe the entire zone cache.

Usage

cf_purge_cache(
  zone_id,
  files = NULL,
  hosts = NULL,
  prefixes = NULL,
  tags = NULL,
  purge_everything = FALSE,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

files

Optional character vector of URLs (or list of list(url = ..., headers = ...) for advanced purges with custom request headers).

hosts

Optional character vector of hostnames whose cached content should be invalidated.

prefixes

Optional character vector of URL prefixes (without scheme) to invalidate, e.g. "example.com/blog".

tags

Optional character vector of cache tags (Enterprise plan).

purge_everything

Logical. When TRUE, ignores the targeted arguments and purges the entire zone cache.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Details

Targeted purges are strictly preferred to wipes because cache wipes can briefly increase origin load. Cloudflare also rate limits the wipe endpoint per zone.

Value

A named list with the purge job id.

Examples

cf_purge_cache("abc123", files = c(
  "https://example.com/index.html",
  "https://example.com/style.css"
))

cf_purge_cache("abc123", purge_everything = TRUE)

Write a value to a Workers KV namespace

Description

Write a value to a Workers KV namespace

Usage

cf_put_kv_value(
  account_id,
  namespace_id,
  key_name,
  value,
  expiration = NULL,
  expiration_ttl = NULL,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

namespace_id

Character. KV namespace identifier.

key_name

Character. Key to read.

value

Character string or raw vector. The value to store.

expiration

Optional integer. Absolute expiration time as a Unix timestamp (seconds).

expiration_ttl

Optional integer. Expiration in seconds from now (minimum 60).

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

TRUE, invisibly, on success.

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_values(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_put_kv_value("abc123", "ns-1", "greeting", "hello world")

Write multiple key-value pairs to a Workers KV namespace

Description

Write multiple key-value pairs to a Workers KV namespace

Usage

cf_put_kv_values(
  account_id,
  namespace_id,
  values,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

namespace_id

Character. KV namespace identifier.

values

A list of entries, each a named list with a key and value element, and optionally expiration, expiration_ttl, metadata, or base64 (see the Cloudflare API docs for the bulk write endpoint). Up to 10,000 entries per call.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list with successful_key_count and unsuccessful_keys.

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_rename_kv_namespace(), cf_workers_invocations()

Examples

cf_put_kv_values(
  "abc123",
  "ns-1",
  list(
    list(key = "greeting", value = "hello"),
    list(key = "farewell", value = "bye", expiration_ttl = 3600)
  )
)

Convert a list of Cloudflare records to a data.frame

Description

Helper that takes a list of named records (typically the result array from a Cloudflare REST endpoint) and returns a data.frame with one row per record. Scalar fields become typed columns; vector- or object-valued fields become list-columns.

Usage

cf_records_to_df(records)

Arguments

records

A list of named lists with broadly consistent field names. Missing fields become NA.

Value

A data.frame with one row per record and columns named by the union of field names. Empty input returns an empty data.frame.

Examples

records <- list(
  list(id = "a", name = "alpha", tags = c("x", "y")),
  list(id = "b", name = "beta",  tags = character(0))
)
cf_records_to_df(records)

Rename a Workers KV namespace

Description

Rename a Workers KV namespace

Usage

cf_rename_kv_namespace(
  account_id,
  namespace_id,
  title,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier.

namespace_id

Character. KV namespace identifier.

title

Character. New namespace name.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the renamed namespace.

See Also

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_workers_invocations()

Examples

cf_rename_kv_namespace("abc123", "ns-1", "sessions-v2")

Build an authenticated request for a Cloudflare endpoint

Description

Returns an httr2 request with credentials, headers, and the endpoint path attached, ready to be piped through httr2 request modifiers (httr2::req_method(), httr2::req_url_query(), httr2::req_body_json()) and performed with httr2::req_perform(). Pair the performed response with cf_resp() to unwrap the standard Cloudflare envelope, or pipe the request into cf_collect() to walk a paginated list endpoint. This is the base that every dedicated wrapper in the package builds on, and the entry point for calling any endpoint that does not yet have one.

Usage

cf_request(endpoint, token = NULL, email = NULL, api_key = NULL)

Arguments

endpoint

Path relative to the API base URL, without a leading slash. Either a single string (for example "zones" or "zones/abc123/dns_records") or a character vector of segments (c("zones", zone_id, "dns_records")); each segment is appended to the URL path via httr2::req_url_path_append().

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

An httr2_request.

See Also

Other requests: cf_collect(), cf_resp()

Examples

cf_request("user/tokens/verify") |>
  httr2::req_perform() |>
  cf_resp()

cf_request(c("zones", "abc123", "dns_records")) |>
  httr2::req_method("POST") |>
  httr2::req_body_json(
    list(type = "A", name = "example.com", content = "192.0.2.1")
  ) |>
  httr2::req_perform() |>
  cf_resp()

cf_request("zones") |>
  httr2::req_url_query(status = "active") |>
  cf_collect(per_page = 50)

Unwrap the result from a Cloudflare response

Description

Validates the standard Cloudflare envelope on a performed response and returns its result payload. Typically the terminal step of a request pipeline built with cf_request() and httr2::req_perform().

Usage

cf_resp(resp)

Arguments

resp

An httr2_response, typically from cf_request(...) |> httr2::req_perform().

Details

The Cloudflare API wraps every response in an envelope with success, errors, messages, result, and (for paginated endpoints) result_info. API-level failures – both HTTP error statuses and envelope errors (HTTP 200 with success: false) – raise a classed condition you can catch with tryCatch(..., cloudflarer_error = ...). Transport-level failures that never reach the API (DNS resolution, connection refused, timeout) surface as the underlying httr2 error instead.

Value

The parsed result element from the response. For single-resource endpoints this is a named list; for collection endpoints it is a list of records.

See Also

Other requests: cf_collect(), cf_request()

Examples

cf_request("user") |>
  httr2::req_perform() |>
  cf_resp()

Daily page views for a Web Analytics (RUM) site

Description

Convenience wrapper around the GraphQL rumPageloadEventsAdaptiveGroups node with a daily (date_DAY) dimension. Returns a tidy data.frame.

Usage

cf_rum_page_views(
  account_id,
  site_tag,
  since,
  until,
  limit = 100L,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier (accountTag in GraphQL).

site_tag

Character. RUM site tag, as returned by cf_list_rum_sites().

since, until

Date or POSIXct (or pre-formatted ISO-8601 character strings). Half-open ⁠[since, until)⁠ interval.

limit

Maximum number of days to return. Cloudflare caps the underlying query at 10000.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame with one row per day and columns date (chr) and pageviews (int).

See Also

Other analytics: cf_cache_ratio(), cf_dns_queries(), cf_firewall_events_by_day(), cf_firewall_events_top(), cf_get_rum_site(), cf_graphql(), cf_list_rum_sites(), cf_rum_top(), cf_workers_invocations(), cf_zone_overview(), cf_zone_requests()

Examples

cf_rum_page_views(
  "acc-1",
  site_tag = "abc",
  since = Sys.Date() - 30,
  until = Sys.Date()
)

Top dimensions for a Web Analytics (RUM) site

Description

Generic wrapper that groups RUM page-load events by a single dimension (country, path, referer, browser, OS, device type, ...) and returns the top entries by count.

Usage

cf_rum_top(
  account_id,
  site_tag,
  since,
  until,
  dimension = "countryName",
  limit = 25L,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier (accountTag in GraphQL).

site_tag

Character. RUM site tag, as returned by cf_list_rum_sites().

since, until

Date or POSIXct (or pre-formatted ISO-8601 character strings). Half-open ⁠[since, until)⁠ interval.

dimension

Character. A dimension name supported by rumPageloadEventsAdaptiveGroups. Common choices: "countryName", "requestPath", "refererHost", "userAgentBrowser", "userAgentOS", "deviceType". Must be a single field name (letters, digits, underscores; not starting with a digit) and cannot be "count", which names the metric column.

limit

Number of rows to return (default 25).

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame with two columns: the requested dimension and count.

See Also

Other analytics: cf_cache_ratio(), cf_dns_queries(), cf_firewall_events_by_day(), cf_firewall_events_top(), cf_get_rum_site(), cf_graphql(), cf_list_rum_sites(), cf_rum_page_views(), cf_workers_invocations(), cf_zone_overview(), cf_zone_requests()

Examples

cf_rum_top(
  "acc-1",
  site_tag = "abc",
  since = Sys.Date() - 7,
  until = Sys.Date(),
  dimension = "countryName",
  limit = 10
)

Cloudflare situation report

Description

Prints a short summary of the package version, which auth mode is configured (cf_auth_mode()), and whether the configured credentials successfully authenticate against the Cloudflare API. Use this as a first stop when debugging configuration issues.

Usage

cf_sitrep()

Value

Invisibly, a list with the diagnostic results.

See Also

Other authentication: cf_api_key(), cf_auth_mode(), cf_email(), cf_has_auth(), cf_token(), cf_verify()

Examples

cf_sitrep()

Cloudflare API token

Description

Returns the modern Cloudflare API token. By default reads from the CLOUDFLARE_API_TOKEN environment variable. See vignette("authentication", package = "cloudflarer") for guidance on creating a token and storing it safely.

Usage

cf_token(token = NULL)

Arguments

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

Value

A character scalar with the API token.

See Also

Other authentication: cf_api_key(), cf_auth_mode(), cf_email(), cf_has_auth(), cf_sitrep(), cf_verify()

Examples

withr::with_envvar(
  c(CLOUDFLARE_API_TOKEN = "cloudflarer-example"),
  cf_token()
)

Update a DNS record

Description

Performs a PATCH on the record, only sending fields supplied as non-NULL. Use a PUT-style replace via cf_request() if you need to overwrite the entire record.

Usage

cf_update_dns_record(
  zone_id,
  record_id,
  type = NULL,
  name = NULL,
  content = NULL,
  ttl = NULL,
  proxied = NULL,
  priority = NULL,
  comment = NULL,
  ...,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

record_id

Character. DNS record identifier.

type

Record type: "A", "AAAA", "CNAME", "MX", "TXT", "SRV", etc.

name

Record name (host). For the apex, pass "@" or the zone name.

content

Record content. For A/AAAA an IP address; for CNAME a hostname; for TXT the string value.

ttl

Time to live in seconds. 1 means "automatic" (Cloudflare's default).

proxied

Logical. Whether the record is proxied through Cloudflare. Applies to A/AAAA/CNAME.

priority

Integer. Required for MX records.

comment

Optional human-readable comment.

...

Additional fields forwarded to the API for record types with extra requirements (data for SRV, etc.).

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the updated record.

See Also

Other dns: cf_create_dns_record(), cf_delete_dns_record(), cf_get_dns_record(), cf_list_dns_records()

Examples

cf_update_dns_record("zone-1", "rec-1", content = "192.0.2.2")

Update a healthcheck

Description

Performs a PATCH, sending only fields supplied as non-NULL.

Usage

cf_update_healthcheck(
  zone_id,
  healthcheck_id,
  name = NULL,
  address = NULL,
  type = NULL,
  check_regions = NULL,
  http_config = NULL,
  tcp_config = NULL,
  interval = NULL,
  retries = NULL,
  timeout = NULL,
  description = NULL,
  suspended = NULL,
  ...,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

healthcheck_id

Character. Healthcheck identifier.

name

Display name for the healthcheck.

address

Hostname or IPv4/IPv6 address to monitor.

type

One of "HTTPS", "HTTP", or "TCP".

check_regions

Optional character vector of Cloudflare region codes ("WEU", "ENAM", etc.). When NULL, the API runs the check from all available regions.

http_config

Optional named list with HTTP/HTTPS-specific fields (path, port, method, expected_codes, expected_body, follow_redirects, allow_insecure, header).

tcp_config

Optional named list with TCP-specific fields (port, method).

interval

Polling interval in seconds.

retries

Number of retries before marking unhealthy.

timeout

Timeout per check, in seconds.

description

Optional human-readable description.

suspended

Logical. When TRUE, the check is paused.

...

Additional fields forwarded to the API.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the updated healthcheck.

See Also

Other healthchecks: cf_create_healthcheck(), cf_delete_healthcheck(), cf_get_healthcheck(), cf_list_healthchecks()

Examples

## Not run: 
cf_update_healthcheck("zone-1", "hc-1", suspended = TRUE)

## End(Not run)

Update a Page Rule

Description

Performs a PATCH. Only supply fields you want to change. Targets and actions are full replacements when supplied.

Usage

cf_update_page_rule(
  zone_id,
  rule_id,
  targets = NULL,
  actions = NULL,
  priority = NULL,
  status = NULL,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

rule_id

Character. Page Rule identifier.

targets

A list of target specifications. The simplest form is a single URL-match created by cf_page_rule_target(); see the example below.

actions

A list of action specifications. The simplest form is a list created by cf_page_rule_action().

priority

Integer. Higher number = applied first.

status

"active" or "disabled".

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list describing the updated rule.

See Also

Other zones: cf_create_page_rule(), cf_delete_page_rule(), cf_get_page_rule(), cf_get_zone(), cf_get_zone_setting(), cf_get_zone_settings(), cf_list_firewall_rules(), cf_list_page_rules(), cf_list_zones(), cf_page_rule_action(), cf_page_rule_target()

Examples

cf_update_page_rule("abc123", "rule-1", status = "disabled")

Get the authenticated user

Description

Returns information about the user that owns the API token.

Usage

cf_user(token = NULL)

Arguments

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

Value

A named list of user fields, including id, email, first_name, last_name, and organizations.

Examples

cf_user()

Verify the active Cloudflare credential

Description

For token auth, calls ⁠/user/tokens/verify⁠ and returns the token record. For Global API Key auth, calls ⁠/user⁠ and returns the user record (the verify endpoint is token-only). Either way, a successful return means the credential authenticates against the API.

Usage

cf_verify(token = NULL, email = NULL, api_key = NULL)

cf_token_verify(token = NULL)

Arguments

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A named list. The shape depends on the auth mode.

See Also

Other authentication: cf_api_key(), cf_auth_mode(), cf_email(), cf_has_auth(), cf_sitrep(), cf_token()

Examples

cf_verify()

Workers invocations over time

Description

Wraps the Cloudflare GraphQL workersInvocationsAdaptive node to return a tidy data.frame with one row per time bin and one row per Worker script.

Usage

cf_workers_invocations(
  account_id,
  since,
  until,
  script_name = NULL,
  limit = 100L,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

account_id

Character. Cloudflare account identifier (accountTag in GraphQL).

since, until

Date or POSIXct. Half-open ⁠[since, until)⁠.

script_name

Optional Worker script name filter.

limit

Maximum number of rows.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Details

Requires an API token with ⁠Account Analytics: Read⁠ (or the legacy Global API Key).

Value

A data.frame with columns date, script, requests, errors, subrequests, duration_ms.

See Also

Other analytics: cf_cache_ratio(), cf_dns_queries(), cf_firewall_events_by_day(), cf_firewall_events_top(), cf_get_rum_site(), cf_graphql(), cf_list_rum_sites(), cf_rum_page_views(), cf_rum_top(), cf_zone_overview(), cf_zone_requests()

Other workers: cf_create_kv_namespace(), cf_delete_kv_namespace(), cf_delete_kv_value(), cf_delete_kv_values(), cf_get_kv_namespace(), cf_get_kv_value(), cf_get_workers_script(), cf_list_kv_keys(), cf_list_kv_namespaces(), cf_list_workers_scripts(), cf_put_kv_value(), cf_put_kv_values(), cf_rename_kv_namespace()

Examples

cf_workers_invocations(
  "acc-1",
  since = Sys.Date() - 7,
  until = Sys.Date()
)

One-call summary of a zone's recent activity

Description

Bundles the most-used analytics endpoints into a single call and returns a named list of tidy data.frames covering traffic, cache effectiveness, DNS queries, firewall events, and (when site_tag is supplied) Web Analytics top countries.

Usage

cf_zone_overview(
  zone_id,
  since = Sys.Date() - 7,
  until = Sys.Date(),
  account_id = NULL,
  site_tag = NULL,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier.

since, until

Date or POSIXct. Half-open ⁠[since, until)⁠. Defaults to the last 7 days.

account_id

Optional account identifier. Required for the top_countries slot.

site_tag

Optional Web Analytics site tag. Required for the top_countries slot.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Details

Each underlying call is wrapped in tryCatch(), so an individual failure (Free-plan gating, missing permission, empty data) yields NULL for that component instead of aborting the whole overview.

Value

A named list with class cloudflarer_overview:

  • traffic – daily requests, bytes, page views, threats, uniques (from cf_zone_requests()).

  • cache – daily cache hit ratios (from cf_cache_ratio()).

  • dns – daily DNS query counts (from cf_dns_queries()).

  • firewall – daily firewall event counts (from cf_firewall_events_by_day(); Pro+ plans only).

  • top_countries – top countries by RUM page views (from cf_rum_top()); only populated when account_id and site_tag are supplied.

  • summary – a one-row data.frame with the period totals.

  • zone_id, since, until – the call's own arguments, echoed back for reference.

See Also

Other analytics: cf_cache_ratio(), cf_dns_queries(), cf_firewall_events_by_day(), cf_firewall_events_top(), cf_get_rum_site(), cf_graphql(), cf_list_rum_sites(), cf_rum_page_views(), cf_rum_top(), cf_workers_invocations(), cf_zone_requests()

Examples

ov <- cf_zone_overview(zone_id, account_id = account_id, site_tag = site_tag)
ov$traffic
ov$summary

Daily or hourly HTTP request totals for a zone

Description

Convenience wrapper around the Cloudflare GraphQL Analytics httpRequests1dGroups (daily) or httpRequests1hGroups (hourly) nodes. Returns a tidy data.frame with one row per time bin and columns for requests, bytes, page views, threats, and unique visitors.

Usage

cf_zone_requests(
  zone_id,
  since,
  until,
  by = c("day", "hour"),
  limit = 100L,
  token = NULL,
  email = NULL,
  api_key = NULL
)

Arguments

zone_id

Character. Cloudflare zone identifier (zoneTag in GraphQL).

since, until

Date or POSIXct (or pre-formatted character "YYYY-MM-DD" for by = "day" and "YYYY-MM-DDTHH:MM:SSZ" for by = "hour"). The interval is half-open ⁠[since, until)⁠.

by

Bin width: "day" or "hour".

limit

Maximum number of bins to return. Cloudflare caps the GraphQL query at 10000.

token

Character. An API token. If NULL (the default), the value of Sys.getenv("CLOUDFLARE_API_TOKEN") is used.

email

Character. Account email. If NULL (the default), reads from the CLOUDFLARE_EMAIL environment variable.

api_key

Character. The Global API Key. If NULL (the default), reads from the CLOUDFLARE_API_KEY environment variable.

Value

A data.frame with columns: date (chr; "YYYY-MM-DD" for daily, "YYYY-MM-DDTHH:00:00Z" for hourly), requests, bytes, pageviews, threats, uniques.

See Also

Other analytics: cf_cache_ratio(), cf_dns_queries(), cf_firewall_events_by_day(), cf_firewall_events_top(), cf_get_rum_site(), cf_graphql(), cf_list_rum_sites(), cf_rum_page_views(), cf_rum_top(), cf_workers_invocations(), cf_zone_overview()

Examples

cf_zone_requests(
  "abc123",
  since = Sys.Date() - 7,
  until = Sys.Date(),
  by    = "day"
)

cf_zone_requests(
  "abc123",
  since = Sys.time() - 24 * 3600,
  until = Sys.time(),
  by    = "hour"
)