DNS Record Import By Txt But Not Clear Old Records

When I Import Dns Record By Txt, It Does Not Clear The Old Records Which Not Exists In The Txt.

I Have To Clear Old Records One By One.

Please Help Me, How To Clear Old Dns Records More Efficiently

That’s correct. An import won’t overwrite existing records.

You could script the change. While I haven’t tested this code it, at first glance seems pretty reasonable.

https://www.tech-otaku.com/web-development/using-cloudflare-api-manage-dns-records/

Then Become A New Question:
How To Clear Old Dns Records More Efficiently??

I Have To Clear Old Records One By One, It’s Too Slow To Do It…

Script the deletes…

api ? i have not found the doc about operate the DNS Records…

i wrote a js to do it,because i have 300+ records

//////////////////////////////////////////////////////////////////////////////

const https = require(‘https’);

const fetch = require(“node-fetch”);

async function getDnsRecords(page){

var url = `https://api.cloudflare.com/client/v4/zones/zoneid/dns_records?per_page=100&page=${page}`

const options = {

    method:'get',

    headers: {

        "X-Auth-Email": "email",

        "X-Auth-Key": "key",

        "Content-Type":"application/json"

    }

}

return await fetch(url, options)

}

async function deleteDnsRecord(record){

var url = `https://api.cloudflare.com/client/v4/zones/zoneid/dns_records/${record.id}`

const options = {

    method:'DELETE',

    headers: {

        "X-Auth-Email": "email",

        "X-Auth-Key": "key",

        "Content-Type":"application/json"

    }

}

return await fetch(url, options)

}

const doit = async ()=>{

var results = []

const response = await getDnsRecords(1);

const json = await response.json();

results = results.concat(json.result)

for(var page = 2; page <= json.result_info.total_pages; ++page){

    const r = await getDnsRecords(page);

    const j = await r.json();

    results = results.concat(j.result)

}

for(const record of results) {

    console.log(record);

    const r = await deleteDnsRecord(record)

    const j = await r.json();

    console.log(j);

}

console.log("all ok")

}

doit()

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