Deleting a list of DNS records

The DNS “import” button adds each record listed in the uploaded file. It would be nice to have a similar “batch delete” button that deletes each record listed in the uploaded file.

2 Likes

I agree and I know this has come up in the past, this may get merged with the earlier request. Best option at the moment is the API, Cloudflare API Documentation

1 Like

If you are not prepared to write your own, there is a nice toolset available from a Cloudflare Community member.

https://cloudflare-utils.cyberjake.xyz/

1 Like

Ended up using the API, thanks. I did pip install cloudflare, generated a token online with DNS edit permissions, and then used the following script.

#!/usr/bin/env python3

import sys
import CloudFlare

with open('token') as f:
  token = f.read().strip()

cf = CloudFlare.CloudFlare(token=token)
zones = cf.zones.get()
id = zones[0]['id']

todo = set()

for line in sys.stdin:
  name,addr = line.split()
  todo.add((name,addr))

dns_records = cf.zones.dns_records.get(id,params={'per_page':10000})

for r in dns_records:
  if r['type'] != 'A': continue
  if (r['name'],r['content']) not in todo: continue
  cf.zones.dns_records.delete(id,r['id'])
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.