[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
12,481
1,966
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
3
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
 
  • Like
Reactions: RadWebHosting

RadWebHosting

Well-Known Member
May 6, 2016
59
13
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.