How to bulk delete CloudFlare DNS at once?
How to bulk delete CloudFlare DNS at once?
Today I faced an issue regarding to remove CF (CloudFlare) DNS records at once. I had more than 50 DNS records for the particular domain. Since I wanted to move to another server I needed to remove all of the records and add new records. As you know currently CF does not provide any GUI option to bulk delete the DNS records. We need to delete one by one. As its taking time, I was able to find out a solutions from the internet. Let me simply explain it to you.
CF has provided bash command to achieve our target. Which mean delete all our DNS records at once. How to do that? First you need to have CF Zone ID & API Key. Zone ID is a unique key specialized for the particular domain.
01. Visit the domain’s overview page then copy the Zone ID.
02. Then click on “Get your API token” and simply create and copy API key. Select “Edit Zone” as the template.
03. Then add those values to below bash command.
zoneid=<ZONE_ID> bearer=<API_KEY> curl --silent "https://api.cloudflare.com/client/v4/zones/$zoneid/dns_records?per_page=50000" \ --header "Authorization: Bearer $bearer" \ | jq --raw-output '.result[].id' | while read id do curl --silent --request DELETE "https://api.cloudflare.com/client/v4/zones/$zoneid/dns_records/$id" \ --header "Authorization: Bearer $bearer" done
04. Run it on your terminal! That’s all!
Thanks for sharing this solution Nimesh, It’s a lifesaver for anyone facing the same issue. Appreciate the effort in simplifying the process and overcoming the challenge of bulk DNS record deletion on Cloud Flare.