[cPanel UAPI] How to get the serial of a DNS zone

Operating System & Version
CentOS v7.9.2009
cPanel & WHM Version
104.0.6
Sep 3, 2018
2
0
1
India
cPanel Access Level
Root Administrator
Hello,

I want to set DNS TXT records with cPanel UAPI from a PHP application. Authentication is done with API Tokens. So I was reading this documentation: Update a DNS zone.

A request sample as per docs:

https://hostname.example.com:2083/cpsess##########/execute/DNS/mass_edit_zone?zone=example.com&serial=202001010100&remove=23

'serial' is a required parameter.

How can I get the serial of a DNS zone using UAPI? I have not found this in the documentation.

Thank you.
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,280
2,434
363
cPanel Access Level
Root Administrator
Hey there! I reached out to the team and there is not an API call available that will provide the serial number. Most people use a grep/awk combination to pull that information manually.

If you'd like to see us add this, could you use the link in my signature to submit a feature request and I'll make sure the development team approves that?
 

santrix

Well-Known Member
Nov 30, 2008
229
4
68
Maybe I'm missing something here, but you can just use whmapi1 dumpzone, then look through the .data -> zone[0] -> record objects for type == 'SOA', then you will find serial in there as a key/value. Or rip it out directly e.g. perl

perl -0777 -ne 'if ($_ =~ m/^([^;][^\n]+\bSOA\b.*?)(\b[0-9]+)/ms){ if ($2 =~ m/([0-9]+)/){print "$ARGV:$1\n"}}' /var/named/domain.db
 

RadWebHosting

Well-Known Member
May 6, 2016
63
14
58
Dallas, Texas
cPanel Access Level
DataCenter Provider
Twitter
Maybe I'm missing something here, but you can just use whmapi1 dumpzone, then look through the .data -> zone[0] -> record objects for type == 'SOA', then you will find serial in there as a key/value. Or rip it out directly e.g. perl

perl -0777 -ne 'if ($_ =~ m/^([^;][^\n]+\bSOA\b.*?)(\b[0-9]+)/ms){ if ($2 =~ m/([0-9]+)/){print "$ARGV:$1\n"}}' /var/named/domain.db
Yeah, I am unclear as to what benefit the UAPI would give since your method could easily be iterated/scaled. Maybe OP can enlighten us.
 

gonzadiaz

Registered
May 17, 2023
1
1
1
Argentina
cPanel Access Level
Root Administrator
Hi, i had that problem that i needed the serial number to use the update zone API. After some investigation i got here and tried the perl script solution. But after sometime experimenting i have found a better way.
Using the "parse_zone" api i get all dns records. Filtering the SOA registry i found in the data field the serial number. The SOA registry has 6 strings inside data_b64 array, the third value in the array is the serial number.
 
  • Like
Reactions: RadWebHosting