Skip to main content

Removing DNS records via the WHM API

Answered

Comments

11 comments

  • RSDS

    I just realised the mistake I made. I had 'remove_dns_record' instead of 'removezonerecord'.

    0
  • cPRex Jurassic Moderator

    Glad you found the cause!

    0
  • RSDS

    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,
    RS
    0
  • cPRex Jurassic Moderator

    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
  • RSDS

    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,
    RS
    0
  • cPRex Jurassic Moderator

    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
  • RSDS

    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
  • RSDS

    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,
    RS
    0
  • cPRex Jurassic Moderator

    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
  • RSDS

    Hi Rex,

    Sorry for the slow response, I managed to get it figured out.

    Cheers,
    RS

    0
  • cPRex Jurassic Moderator

    Glad to hear it!

    0

Please sign in to leave a comment.