Skip to content

Using the command-line script

cloudflare-api is useful for a quick lookup or a shell script that already has credentials in its environment. Choose a resource and action for a named method. Output is pretty JSON unless you ask for dumper:

cloudflare-api --resource zones --action list --param status=active
cloudflare-api --resource r2 --action list_buckets --full-response
cloudflare-api --resource zones --action list --output dumper

A --param passes a named string argument, usually a list filter. --arg passes a positional string argument, in the order given. For a method expecting a JSON body, use a typed argument rather than a string:

cloudflare-api --resource kv --action create_namespace \
    --arg-json '{"title":"my-app-cache"}'
cloudflare-api --resource workers --action upload_assets \
    --arg my-app --arg dist/site --param prefix=/docs

For selected files, give the Worker name with --arg, then combine repeatable --asset FILE, --asset-list-json FILE, and --asset-list-text FILE. Use --asset-list-stdin once to read one filename per line from standard input. Text lists ignore blank lines and preserve spaces in filenames. JSON lists contain arrays of filenames or objects with path, optional URL name, and optional content_type. Bare filenames use their basenames as URL paths; use a directory source or explicit JSON names to preserve nested paths. Do not mix these list options with a second source argument.

cloudflare-api --resource workers --action upload_assets \
    --arg my-app --asset dist/index.html --asset-list-text images.txt \
    --param prefix=/docs

Typed positional forms include --arg-bool, --arg-array, --arg-hash, --arg-json, and --arg-json-file. Named forms include --param-bool, --param-json, and --param-json-file. The JSON file forms are handy for longer bodies; for example, a Worker upload can take its name through --arg and prepared metadata and files through --param-json-file.

The command deliberately makes one request for a list action unless --paginate is supplied. With --paginate, it returns an array of page results, preserving each page boundary. Without --max-pages, it follows every page Cloudflare reports:

cloudflare-api --resource kv --action list_namespaces \
    --paginate --per-page 20 --max-pages 2 --full-response

The command retains those pages in memory before printing them. For a very large result set, use --max-pages to bound the command or use the Perl _page() interface to process items incrementally.

The lower-level form uses --method and --path instead of a resource and action:

cloudflare-api --method GET --path /accounts --full-response

Use --help for a short reminder, --man for the complete option reference, or --version for the installed version. The command also has --account-id and --output json|dumper.

Warning

The --arg-dumper-file and --param-dumper-file options evaluate the file as Perl code. Use them only with files you trust; prefer JSON for data from elsewhere. --dump-opt prints parsed arguments and can expose values. For secret-bearing bodies, avoid shell arguments and output logs; the script's manual describes how to read a JSON body from standard input.