Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BirkhoffLee/ad3b869c0027881da7bde82c815066b9 to your computer and use it in GitHub Desktop.
Save BirkhoffLee/ad3b869c0027881da7bde82c815066b9 to your computer and use it in GitHub Desktop.
Delete all DNS records for specified zone
#!/bin/bash
TOKEN="xxxxxxxxxxxxxxxxxxx"
ZONE_ID=2222222222222222222222222
# EMAIL=me@gmail.com
# KEY=11111111111111111111111111
# Replace with
# -H "X-Auth-Email: ${EMAIL}" \
# -H "X-Auth-Key: ${KEY}" \
# for old API keys
curl -s -X GET https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?per_page=500 \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" | jq .result[].id | tr -d '"' | (
while read id; do
curl -s -X DELETE https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${id} \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json"
done
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment