DELETE all records using API

Hi,

Currently I am trying to automate the move of many domains from an existing DNS service provider to Cloudflare. I am using the API to do this: https://api.cloudflare.com/

The problem I encounter is that when I add a new zone via the API then it automatically queries its current DNS settings and adds them into Cloudflare.

Is it possible to change this behavior so when a new zone is added it gets added with no records at all? Or is there an API call that I can use to DELETE all current records rather than one by one?

Please let me know.
Thanks in advance.

1 Like

Hey there,

There isn’t a bulk delete call, I’m afraid. However, you should be able to script this.
List the DNS records, filter for the ID and pass that into the delete call.
Hope this helps.

1 Like

Hi,

Too bad. Then I guess I will have to do the lookup first.

Thanks!

If you add the zone via API I believe you can tell us not to scan existing records:

https://api.cloudflare.com/#zone-create-a-zone

Set jump_start to false. Obviously at that point you’re on the hook for creating whatever DNS records need to be created in your zone (via API, BIND file import or manual creation).

HTH,

Chris

3 Likes

Thanks!. That is exactly what I was looking for.

Me again,

What if I am using the host API at https://api.cloudflare.com/host-gw.html with a partners.Cloudflare.com account?

I tried to pass the -d ‘jump_start=false’ to https://api.cloudflare.com/host-gw.html but that did not do anything

Please let me know
Thanks!

Hmm… I don’t see it listed in our internal docs either. We are working on improving parity/ consolidating some APIs to make things easier for partners and this may be on the list.

Course I could also be just flat out wrong, I’d recommend pinging support to see if they have a better answer. They’re way smarter than I am when it comes to the partner APIs. :wink:

1 Like

Creating the zone via the API is very quick and works perfectly!

To make it even quicker, I suggest using Postman and importing the Postman collection from Cloudflare:

Then, you only need to create a Postman environment for the variables x-auth-email (your account’s email) and x-auth-key (the Global key you can find in your Cloudflare profile).

Cheers,
Guido

PS: the documentation link has changed => https://api.cloudflare.com/#zone-create-zone

Hi Mr.@cs-cf, how can I add some specific DNS records under my domain using API call? currently i use create zone API by setting jump_start = false. then calling Scan API “https://api.cloudflare.com/client/v4/zones/".$zoneid."/dns_records/scan” ---- which create 7 records But I want to have only 4 records. How can I do that in one API call?

you can check my question with more details here: How to create some certain dns records using API

any guidance or suggestion would be appreciated.
Thanks!

Regards,
Zahir

You can’t. You can either use a BIND file as @sdayman suggested in the other thread or make a call for each record you want to create. You can dynamically create the BIND file, or you can call and create the individual records.

3 Likes

Why is this made so difficult for users? Why not a button on the dashboard… okay, I can understand, but still, would be awesome! But why not even through the API? I think users who use the API know what they’re doing, right?

Hey, I built a tool to bulk-delete DNS records. Check it out: https://cloudflare-dns-th0th.vercel.app (the source code is here: GitHub - th0th/cloudflare-dns: A simple tool for bulk-deleting DNS records on CloudFlare.)