-
-
Save slayer/442fa2fffed57f8409e0b23bd0673a92 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
TOKEN="xxxxxxxxxxxxxxxxxxx" | |
ZONE_ID=2222222222222222222222222 | |
# [email protected] | |
# 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 | |
) | |
I have a simpler approach, just paste some JS in your browser console:
https://gist.github.com/AidasK/9550e1eb97b3b121c5122aef0d778608
Thanks, this seem like the easiest soæution. All though I can only get the script to delete the current record.
Can you elaborate on where I paste and fire the script?
Standing on the DNS-page it doesent do much.
I love you
To get Zone ID using domain name
ZONE_ID=$(curl -s -H "Authorization: Bearer $TOKEN" -H "Content-Type:application/json" -X GET "https://api.cloudflare.com/client/v4/zones?name=$domain"| jq -r '.result[] | {id} | .id')
Thank you, does exactly what I need it to do
awesome!!! <3
Worked a treat; thanks. But note that almost nobody will have 'jq' installed, or have even heard of it. On Deb/Ubuntu, 'apt install jq'.
Initial code has jq
so I've used as well. But agree that extra tool could be missed at user's shell.
do you have script to delete specific domain ?
@pr4ns sure, I wrote this for you based on the Cloudflare REST API docs here
#!/bin/bash
# permission needed: #zone:edit
TOKEN="xxxxxxxxxxxxxxxxxxx"
ZONE_ID=2222222222222222222222222
# [email protected]
# KEY=11111111111111111111111111
# Replace with
# -H "X-Auth-Email: ${EMAIL}" \
# -H "X-Auth-Key: ${KEY}" \
# for old API keys
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json"
Tested and working 👍
thanks a lot. it works for me
Thanks
works perfect and thanks a lot !
Thank you! Ridiculous that you can't add a new zone without copying all the old DNS records from the previous domain owner.
Thanks,
The code works like a charm on wsl ubuntu
It took 3min to remove 600+ dns records
thank you <3