cf manages Cloudflare resources directly, without a Workers project. This
guide uses DNS records to show a pattern that most resource commands follow:
find a resource, list what it contains, preview a change, make the change, and
clean up.
- Install
cfand sign in. If you use an API token, it needs permission to edit DNS records in the zone. - Add a domain to your Cloudflare account. This guide uses
example.com. - (Optional) Install
jq↗︎ to filter JSON output.
List the zones you can access:
cf zones listThe result is a JSON array. To look up one domain, filter by name:
cf zones list --name example.comNote the id of the zone. Zone-scoped commands accept the zone ID or the
domain name. For details, refer to
Select a zone.
List the DNS records in the zone:
cf dns records list --zone example.comOptions narrow the results. For example, list only A records:
cf dns records list --zone example.com --type Acf dns records list returns one page of results. To request more pages, pass
--page and --per-page (or check a command's --help output for
cursor-based options such as --cursor).
Paginated cf list commands print page items as JSON on standard output
(stdout) so you can pipe them directly to jq, and write API pagination
metadata to standard error (stderr) as a result_info: line:
result_info: {"page":1,"per_page":100,"count":100,"total_count":142,"total_pages":2}When scripting across pages, capture stdout and stderr separately — do not
merge 2>&1 into a stdout JSON parser — and omit --quiet (-q) so cf
still prints result_info: on stderr:
cf dns records list --zone example.com --page 1 --per-page 50 >page.json 2>meta.err
result_info=$(sed -n 's/^result_info: //p' meta.err | tail -n 1)Add --dry-run to see the request a command would send. A dry run prints the
method, URL, and body as JSON, and exits without sending anything. It does not
need credentials.
cf dns records create --zone <ZONE_ID> --body '{"type":"A","name":"test","content":"192.0.2.1","proxied":true}' --dry-run{
"command": "cf dns records create",
"method": "POST",
"url": "https://api.cloudflare.com/client/v4/zones/<ZONE_ID>/dns_records",
"pathParams": {
"zone-id": "<ZONE_ID>"
},
"query": {},
"bodyKind": "json",
"body": {
"type": "A",
"name": "test",
"content": "192.0.2.1",
"proxied": true
}
}Use the zone ID in a dry run. A dry run does not look up domain names, so the preview would show the domain name where the ID belongs.
--body takes the JSON request body. Some operations, including this one,
accept their input only through --body. For the fields the body accepts,
refer to the
Create DNS Record API reference.
Run the same command without --dry-run:
cf dns records create --zone example.com --body '{"type":"A","name":"test","content":"192.0.2.1","proxied":true}'cf prints the new record as JSON, including its id.
Because results are JSON on standard output, you can pipe them to jq. Print
the name and content of each A record:
cf dns records list --zone example.com --type A | jq -r '.[] | "\(.name) \(.content)"'Get the ID of the record you created:
cf dns records list --zone example.com --name test.example.com | jq -r '.[0].id'Delete the record by its ID:
cf dns records delete <RECORD_ID> --zone example.comcf asks you to confirm before it deletes anything. The default answer is no.
In a non-interactive session, such as a script or CI job, cf cannot ask. It
prints the question and Aborted., makes no change, and exits with status 1.
To delete without confirmation, pass --force:
cf dns records delete <RECORD_ID> --zone example.com --forceDescribe a task to find the command for it:
cf cli search "purge cached files for a URL"cf cli search prints up to five matching commands as JSON, best match first.
Each match includes the command and a short summary. It runs locally and does
not need credentials.
To see the arguments and options a command accepts, add --help:
cf cache purge --helpTo see the API request a generated command sends, including its method, path,
parameters, and body fields, pass it to cf schema:
cf schema zones createTo browse commands by product, add --help to cf, to a product such as
cf dns, or to any command.
- Run
cffrom scripts and pipelines with Usecfin CI. - Give a coding agent access to the same commands with
Use
cfwith coding agents.