Using mass_edit_zone API function

swbrains

Well-Known Member
Sep 13, 2006
264
37
178
When using the mass_edit_zone API function, it requires the current serial number to be passed as an input parameter.

I can call parse_zone to get the DNS records for the zone and isolate the SOA record, which contains the serial number. However, I can't see how to identify which of the lines in the returned data_b64 field is the serial in my app. I can tell by visually looking at the data, but there doesn't seem to be any text to identify the different values in this field.

1) Is there a better or more precise way to get the zone serial number to be used in mass_edit_zone (rather than just extracting the number that "looks" like a serial)?

2) Are there distinct functions for adding, deleting, and updating DNS records aside from mass_edit_zone that don't require serial?

I've been using add_zone_record and remove_zone_record, but they don't appear in the latest API docs any more so I'm assuming they are deprecated and mass_edit_zone is their single replacement. Please let me know if this is incorrect.

Thanks,
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
10,360
1,631
363
cPanel Access Level
Root Administrator

swbrains

Well-Known Member
Sep 13, 2006
264
37
178
Another question about mass_edit_zone:
Code:
/mass_edit_zone?zone=$host&serial=$serial&add=$json[\code]
When I want to add a DNS record like an SPF record, the host name on the final DNS record should be just "example.com".
If I specify the following for the add= json:
[code] {"dname":"example.com", "ttl":14400, "record_type":"TXT", "data":["v=spf1 a mx ip4:11.22.33.44 ~all"]}
The resulting DNS record in cPanel shows up with a host name of "example.com.example.com", as if the API is combining dname and zone to get the final record's host name.

If I try to compensate by specifying an empty dname in the json, then the API returns an error "each add requires a dname...".

How do I use mass_edit_zone to create an DNS record where the record's host name is simply the domain name (zone)?
 

swbrains

Well-Known Member
Sep 13, 2006
264
37
178
I've resolved the last issue with mass_edit_zone. The function allows you to specify a dname parameter of simply "sample" and it will create a DNS record with the name "sample.example.com" (if your domain is example.com). In that case, it appears to do the concatenation for you if the domain is not specified in the dname parameter.

However, it won't allow dname to be blank. So if you try to set dname to the domain, "example.com", you get a final record of "example.com.example.com".

But apparently, if you specify the dname as the domain name AND a trailing period (.) : "example.com.", then it leaves it alone and creates the record with the specified dname without adding the domain to it again.

So it appears the function tries to be intelligent and adds the domain to the dname if the dname doesn't include it, or perhaps if there is no trailing period in dname. If you need *nothing* added to the domain for the record's name (i.e. you want the DNS record name to be simple "example.com", you need to specify "example.com." with the trailing period as your dname parameter.

I don't know if developers are expected to always include the entire record name including the domain and trailing period for all add operations, but if that's the case, the function probably shouldn't make assumptions and allow you to do otherwise by adding the domain to the name internally if not specified in dname.

I'm posting this solution here for future developers to find, but this would again be very useful information for the documentation page with regard to the "add" function and the "dname" parameter description.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
10,360
1,631
363
cPanel Access Level
Root Administrator
I would expect the trailing dot to be standard syntax for any DNS zone work. Is that not what you're experiencing? I see a few other typos on that page that I'll submit at the same time, but I just want to make sure I'm understanding what clarification you're looking for.