By Greg Nowak. Last updated 2026-07-11.
If you are looking for browser-console JavaScript to bulk-delete Cloudflare DNS records, you probably have a cleanup problem rather than a JavaScript problem: an untidy import, a completed migration, or years of records left behind by former vendors.
Running a click-loop in DevTools used to feel like the quickest answer. It was also brittle. A dashboard update could break the script halfway through, while an overly broad selector could remove records you never intended to touch. Cloudflare now provides first-party bulk operations in its dashboard and API. The safer question is therefore not “How can I click Delete faster?” but “Which workflow gives us a reviewable change and a credible recovery path?”
Choose the right cleanup method
| Situation | Best method | Why |
|---|---|---|
| One zone with an obvious selection | Dashboard bulk delete | Fast, visible, and easy for a colleague to review |
| Records match a clear rule | List and delete through the API | Repeatable filtering with an explicit preview |
| Deletes and replacements belong together | Batch API | One reviewed request containing the complete change set |
| The zone needs extensive reconstruction | Export, edit, and import | A before-and-after file is often clearer than hundreds of individual actions |
Use dashboard bulk delete for straightforward jobs
On the DNS Records page, select the records, choose Delete records, and type DELETE when prompted. As of July 2026, Cloudflare makes this available on every plan. One action can include up to 200 records on Free zones and 3,500 on Pro, Business, and Enterprise zones.
This is usually the best option when a human can confidently identify the records. Before confirming, export the zone and save the file with the change ticket. Treat that export as recovery material, not a magic Undo button: restoration still needs to be checked carefully.
Review these records separately before any broad deletion:
MX, SPF, DKIM, and DMARC records that protect email delivery;TXTrecords used for domain ownership or SaaS verification;CAA,SRV, and delegatedNSrecords;- records supporting customer logins, redirects, certificates, or migration fallbacks.
For repeatable cleanup, preview through the API
Use a narrowly scoped API token with DNS Read for discovery and DNS Write only when deletion is required. Cloudflare recommends API tokens instead of the older Global API Key.
The list endpoint supports structured filters for type, name, content, tags, and comments. Avoid building automation around its free-text search parameter: Cloudflare explicitly reserves that feature for human use and may change its behaviour.
The following example downloads a snapshot, checks that Cloudflare reported success, and creates a reviewable list of matching TXT records. Replace the example domain and selection rule before running it:
export ZONE_ID="your_zone_id"
export CLOUDFLARE_API_TOKEN="your_token"
curl --fail-with-body --silent --show-error \
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?per_page=50000" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
> dns-records.json
jq -e '.success == true' dns-records.json > /dev/null
jq -r '.result[]
| select(
.type == "TXT" and
(.name == "old.example.com" or
(.name | endswith(".old.example.com")))
)
| [.id, .type, .name, .content]
| @tsv' dns-records.json > candidates.tsv
wc -l candidates.tsv
column -t -s $'\t' candidates.tsvStop here and inspect candidates.tsv. Confirm the count, names, values, and business purpose with whoever owns the affected service. For zones exceeding the requested page size, process every page reported in result_info.total_pages; never assume that one response contains the whole zone.
Delete only the reviewed record IDs
Once the candidate file has been approved, feed its first column to the documented delete endpoint:
cut -f1 candidates.tsv > approved-record-ids.txt
while IFS= read -r id; do
curl --fail-with-body --silent --show-error \
--request DELETE \
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$id" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
echo
done < approved-record-ids.txtKeeping discovery and deletion as separate steps is intentional. It produces an approval artifact, prevents a changing query from silently expanding the deletion, and makes the operation easier to audit. Do not place long-lived tokens in source control, shared chat, or shell scripts committed to a repository.
Use the batch endpoint for coordinated changes
If records must be deleted and replaced during the same change window, Cloudflare’s /dns_records/batch endpoint can carry deletes, patches, puts, and posts in one request. Operations run in that order. A minimal deletion body looks like this:
{
"deletes": [
{ "id": "RECORD_ID_1" },
{ "id": "RECORD_ID_2" }
]
}Cloudflare executes a batch as one database transaction, but propagation across its distributed network is not atomic. Clients may briefly observe different stages of a coordinated change. Plan the sequence, retain old destinations where practical, and validate the finished state rather than assuming a successful API response proves the service works.
Finish with service-level checks
- List the zone again and confirm that only approved IDs disappeared.
- Resolve important names through more than one public DNS resolver.
- Test the website, redirects, email flow, certificate issuance, and vendor verification affected by the change.
- Record what was removed, who approved it, and where the export and candidate list are stored.
For a deeply cluttered zone, rebuilding from a reviewed export may be clearer than running hundreds of deletes. Cloudflare currently limits imported zone files to 256 KiB and the import API to three requests per minute per user, so include those constraints in the plan.
If your zone supports revenue, email, or customer access and nobody is entirely sure which records are still needed, Greg can help turn the cleanup into a controlled DNS change with clear ownership, review, and validation.
Related on GrN.dk
- AI automations need a spend dashboard before the first runaway bill
- When AI writes JSON, one bad field can break the workflow
- AI search is eating the click: measure the queries before rewriting pages
Need help with this kind of work?
Plan a safer DNS cleanup with Greg Get in touch with Greg.