vb543

Member
Jan 22, 2015
9
0
1
cPanel Access Level
Root Administrator
I'm quite new to this so I'd appreciate some help. I'm currently trying to write a PHP script to create an SRV record for an existing domain name. I receive "Invalid DNS record: Supplied target for SRV record is invalid" with the following code:
Code:
$xmlapi = new xmlapi('serverExternalIP');
$xmlapi->password_auth("root","rootpw");
$xmlapi->set_output('json');
$xmlapi->set_debug(1);

print $xmlapi->api2_query("cPanelUserAccount", "ZoneEdit", "add_zone_record",  array(
  'domain' => 'mydomain.com', #Already an addon domain for the account
  'name' => '_minecraft._tcp.test1.mydomain.com', #Took this from a working SRV record I created using the advanced web editor
  'type' => 'SRV',
  'txtdata' => 'target=server1.mydomain.com,port=25656', #server1.mydomain.com has an existing A record
  'ttl' => '300',
  'class' => 'IN',)
  );
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,224
463
Hello,

The following values are possible when using cPanel API 2 to add a zone record per our documentation:

A
CNAME
TXT

You will need to use WHM API 1 to add the SRV record with our API:

WHM API 1 - Add Zone Record

Thank you.
 

vb543

Member
Jan 22, 2015
9
0
1
cPanel Access Level
Root Administrator
Thanks!

In hopes of confirming I'm at least doing the basics correctly, I have the following line to dumpzone. Unfortunately, it's not working either. Any idea where I'm going wrong?

Code:
print $xmlapi->api1_query("cPanelUsernName", "Email", "dumpzone", array($domain));
Output
Code:
{"apiversion":"1","type":"event","module":"Email","func":"dumpzone","source":"module","data":{"result":""},"event":{"result":1}}
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,224
463
Hello,

Would you mind sharing the full script (minus any actual password hashes) you are using when utilizing the dumpzone WHM API 1 function? I tested with a URL such as:

Code:
https://10.1.1.1:2087/cpsess9622297555/json-api/dumpzone?api.version=1&domain=cptest01.com
This correctly dumped the zone in the output.

Thank you.
 

vb543

Member
Jan 22, 2015
9
0
1
cPanel Access Level
Root Administrator
Here's the dumpzone script.
Code:
<?php

include './xmlapi.php';
$domain = "testdomain.com";

$xmlapi = new xmlapi('10.1.1.1');
$xmlapi->password_auth("root","rootPass");
$xmlapi->set_output('json');

$xmlapi->set_debug(1);

print $xmlapi->api1_query("cPanelUserAccount", "Email", "dumpzone", array($domain));

?>
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,224
463
You could try something like this:

Code:
<?php

include './xmlapi.php';
$domain = "test01.com";

$xmlapi = new xmlapi('1.1.1.1');
$xmlapi->password_auth("root","password");

$xmlapi->set_debug(1);
$xmlapi->set_output('json');
print  $xmlapi->dumpzone( $domain );
Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,224
463

vb543

Member
Jan 22, 2015
9
0
1
cPanel Access Level
Root Administrator
Thanks for the examples. Based on the api1 example, I wrote the following code. Unfortunately, it does not seem to be working. Any idea where I'm going wrong?

Code:
<?php

include './xmlapi.php';

$xmlapi = new xmlapi('serverIP');
$xmlapi->password_auth("root","rootpw");
$xmlapi->set_output('json');

$xmlapi->set_debug(1);

print $xmlapi->api1_query("account", "Email", "addzonerecord",  array(
        'domain' => 'example.com',
        'name' => '_minecraft._tcp.test20.example.com',
        'type' => 'SRV',
        'port' => '25656',
        'priority' => '0',
        'weight' => '0',
         'target' => 'mc1.example.com',
        'ttl' => '360',
        'class' => 'IN',)
        );
?>
Output:

Code:
{"apiversion":"1","type":"event","module":"Email","func":"addzonerecord","source":"module","data":{"result":""},"event":{"result":1}}
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,224
463
print $xmlapi->api1_query("account", "Email", "addzonerecord", array(
Hello,

I see a few issues with your custom script, but the most notable is you are referencing the "Email" module. You will likely want to consult with a qualified system administrator or developer if you are not comfortable with developing the script on your own. We are happy to offer guidance, but we won't be able to develop each custom script for you. The following option in Web Host Manager is a good way to test the module:

"WHM Home » Development » API Shell"

Note you must first enable "cPanel & WHM API shell (for developers)" under the "System" tab in "WHM >> Tweak Settings".

Thank you.
 

vb543

Member
Jan 22, 2015
9
0
1
cPanel Access Level
Root Administrator
I appreciate your help and I understand that you're not here to write my script for me, I was just trying to understand the examples for a basic api call.

After realizing that there's a great deal of documentation hidden beneath the zmlapi.php file, I was able to get the addzonerecord working. Now my issue is with regards to the name field. It's duplicating the domain name and I'm not sure how to work around this. The API shell did the same thing, so it's probably an issue with my data.
Code:
  'domain' => 'domain.com',
  'name' => '_service._tcp.test20.domain.com',
Yields the following for the record's Name:
Code:
 _service._tcp.test20.domain.com.domain.com.
I've tried removing the 'domain.com' part from the name field but that resulted in an error.

Any ideas? Thanks!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,224
463
The API shell did the same thing, so it's probably an issue with my data.
Hello,

The name entry should be:

Code:
_service._tcp.test20
Thank you.
 
  • Like
Reactions: vb543