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 get more, use --page
and --per-page.
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 0.
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.