Skip to content

Instantly share code, notes, and snippets.

@siberex
Last active December 7, 2022 10:20
Show Gist options
  • Save siberex/1b49208d5f6f40622a67a58027be7845 to your computer and use it in GitHub Desktop.
Save siberex/1b49208d5f6f40622a67a58027be7845 to your computer and use it in GitHub Desktop.
CloudFlare API cheatsheet

Get Token

CF_TOKEN="..."

curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
     -H "Authorization: Bearer $CF_TOKEN"

List zones

curl -X GET "https://api.cloudflare.com/client/v4/zones" \
     -H "Content-Type:application/json" \
     -H "Authorization: Bearer $CF_TOKEN" \
     | jq -r '(.result[] | [.id, .name]) | @tsv'

Get Zone ID by name:

CF_ZONE_NAME="sib.li"
curl -X GET "https://api.cloudflare.com/client/v4/zones?name=$CF_ZONE_NAME&status=active" \
     -H "Content-Type:application/json" \
     -H "Authorization: Bearer $CF_TOKEN" \
     | jq -r '.result[].id'

List records by Zone ID

CF_ZONE_ID="..."
curl -X GET "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/dns_records" \
     -H "Content-Type:application/json" \
     -H "Authorization: Bearer $CF_TOKEN" \
     | jq -r '(.result[] | [.id, .type, .name, .content]) | @tsv'

List records by name and type:

curl -X GET "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/dns_records?name=$CF_ZONE_NAME&type=A" \
     -H "Content-Type:application/x-yaml" \
     -H "Authorization: Bearer $CF_TOKEN" \
     | jq -r '(.result[] | [.id, .type, .name, .content]) | @tsv'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment