Removing DNS records via the WHM API
AnsweredHi folks,
I'm producing a script which is intended to duplicate a DNS zone and so far it's creating the new zone with the IP address as expected but it's adding records which are likely to clash with the old zone's records when I copy them across, namely the default MX record and the www, ftp, and mail CNAME records.
When I have my script loop through them collecting the required line numbers, I'm presented with the following error for each of them upon running the removezonerecord endpoint:
Unknown app (“remove_dns_record”) requested for this version (1) of the API.
I've examined the server and can confirm that the DNS role is enabled, so it's unclear as to why this is occurring.
Any ideas?
-
I just realised the mistake I made. I had 'remove_dns_record' instead of 'removezonerecord'.
0 -
Glad you found the cause!
0 -
Hi Rex,
I'm finding that after removing a record the lines are re-indexed, meaning the zone has to be loaded via dumpzone again for each removal. Do you have a logic you might suggest I use to most efficiently loop over the zone and remove the unwanted records?
Cheers,RS0 -
I don't believe I have a good answer for that one. The API is designed to remove one line at a time, as you've found, so multiple iterations may be the only option.
0 -
That's fair enough.
Do you have any idea how long dumpzone might still be part of the code? I can see that it's deprecated. I ask because for some reason I can't get my code working (same logic) working with parse_dns_zone the way I can with dumpzone, it can't seem to keep up with the indexes.
Cheers,RS0 -
There's currently no plans that I'm aware of to kill off any of the "deprecated" API calls - some have existed in that state for 10+ years.
0 -
Excellent :)
I'm going to continue tinkering with the parse_dns_zone output, but if I can't get it working I'll fall back on dumpzone.
0 -
Hi Rex,
With the zone duplication script I'm building, you wouldn't happen to have an example JSON output from parse_dns_zone with all of the different record types on addzonerecord I could reference, would you? There's a whole slew of records in there which I've never had a need to use previously and thus I'm not familiar with but I would like this script to be thorough when making a duplicate.
Cheers,RS0 -
I'm not entirely sure what you're looking for in an example, but the data for addzonerecord would all be found here:
https://api.docs.cpanel.net/openapi/whm/operation/addzonerecord/
The parse_dns_zone output run against even a default zone that is created on the server would give you a ton of output - here's what a test zone looks like on my system, complete with a typo in the domain name:
# whmapi1 --output=jsonpretty parse_dns_zone zone='dnsteset.com'
{
"data" : {
"payload" : [
{
"line_index" : 0,
"text_b64" : "OyBjUGFuZWwgZmlyc3Q6MTI0LjAuMTcgKHVwZGF0ZV90aW1lKToxNzMzMTk0NDUxIENwYW5lbDo6Wm9uZUZpbGU6OlZFUlNJT046MS4zIGhvc3RuYW1lOmhvc3QuaGF0dG1vbmtleS5jb20gbGF0ZXN0OjEyNC4wLjE3",
"type" : "comment"
},
{
"line_index" : 1,
"text_b64" : "OyBab25lIGZpbGUgZm9yIGRuc3Rlc2V0LmNvbQ==",
"type" : "comment"
},
{
"line_index" : 2,
"text_b64" : "JFRUTCAxNDQwMA==",
"type" : "control"
},
{
"data_b64" : [
"bnMxLmhhdHRtb25rZXkuY29tLg==",
"cmpcLmhhdHQuYXR0Lm5ldC4=",
"MjAyNDEyMDMwMA==",
"MzYwMA==",
"MTgwMA==",
"MTIwOTYwMA==",
"ODY0MDA="
],
"dname_b64" : "ZG5zdGVzZXQuY29tLg==",
"line_index" : 3,
"record_type" : "SOA",
"ttl" : 86400,
"type" : "record"
},
{
"data_b64" : [
"bnMxLmhhdHRtb25rZXkuY29tLg=="
],
"dname_b64" : "ZG5zdGVzZXQuY29tLg==",
"line_index" : 9,
"record_type" : "NS",
"ttl" : 86400,
"type" : "record"
},
{
"data_b64" : [
"bnMyLmhhdHRtb25rZXkuY29tLg=="
],
"dname_b64" : "ZG5zdGVzZXQuY29tLg==",
"line_index" : 10,
"record_type" : "NS",
"ttl" : 86400,
"type" : "record"
},
{
"data_b64" : [
"MTcyLjEwNS4xMDcuMTUy"
],
"dname_b64" : "ZG5zdGVzZXQuY29tLg==",
"line_index" : 11,
"record_type" : "A",
"ttl" : 14400,
"type" : "record"
},
{
"data_b64" : [
"MA==",
"ZG5zdGVzZXQuY29tLg=="
],
"dname_b64" : "ZG5zdGVzZXQuY29tLg==",
"line_index" : 12,
"record_type" : "MX",
"ttl" : 14400,
"type" : "record"
},
{
"data_b64" : [
"ZG5zdGVzZXQuY29tLg=="
],
"dname_b64" : "d3d3",
"line_index" : 13,
"record_type" : "CNAME",
"ttl" : 14400,
"type" : "record"
}
]
},
"metadata" : {
"command" : "parse_dns_zone",
"reason" : "OK",
"result" : 1,
"version" : 1
}
}0 -
Hi Rex,
Sorry for the slow response, I managed to get it figured out.
Cheers,
RS0 -
Glad to hear it!
0
Please sign in to leave a comment.
Comments
11 comments