Skip to content

Instantly share code, notes, and snippets.

@MOZGIII
Created March 29, 2021 13:26
Show Gist options
  • Save MOZGIII/a5fce318d95a5af09dcc69fec75fdef2 to your computer and use it in GitHub Desktop.
Save MOZGIII/a5fce318d95a5af09dcc69fec75fdef2 to your computer and use it in GitHub Desktop.
Bulk DNS records removal from Cloudflare
#!/bin/bash
set -euo pipefail
AUTH_TOKEN="$1"
ZONE_ID="$2"
api() {
curl -sSL -H "Authorization: Bearer $AUTH_TOKEN" "$@"
}
get_records() {
api "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records"
}
delete_record() {
local ID="$1"
api -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$ID"
}
IDS=$(get_records | jq -r '.result | .[].id')
for ID in $IDS; do
echo "$ID"
delete_record "$ID"
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment