CloudFlare API

Simple Bash Script to Delete existing Cloud Flare entries,
useful when you want to cleanup Cloudflare quickly

You will have to create an API Key and get your Zone Id to use this script.

USE CAREFULLY, it will delete everything !

#!/bin/bash

ZONE_ID=""
API_KEY=""

entries=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \
        -H "Authorization: Bearer $API_KEY" \
        -H "Content-Type: application/json" | jq .result)

for item in $(echo $entries | jq -r '.[] | @base64'); do
    _jq() {
        echo ${item} | base64 --decode | jq -r ${1}
    }

    entryId=$(echo $(_jq '.') | jq -r .id)
    curl -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$entryId" \
        -H "Authorization: $API_KEY" \
        -H "Content-Type: application/json"
done