The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

xmlapi add SRV record

Discussion in 'cPanel Developers' started by vb543, Jun 1, 2015.

  1. vb543

    vb543 Member

    Joined:
    Jan 22, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    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',)
      );
    
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,807
    Likes Received:
    667
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  3. vb543

    vb543 Member

    Joined:
    Jan 22, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    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}}
    
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,807
    Likes Received:
    667
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  5. vb543

    vb543 Member

    Joined:
    Jan 22, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    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));
    
    ?>
    
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,807
    Likes Received:
    667
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  7. vb543

    vb543 Member

    Joined:
    Jan 22, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks, that worked for the dumpzone. Could you provide an example for addzonerecord for an SRV record?

    Much appreciated.
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,807
    Likes Received:
    667
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  9. vb543

    vb543 Member

    Joined:
    Jan 22, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    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}}
    
     
  10. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,807
    Likes Received:
    667
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  11. vb543

    vb543 Member

    Joined:
    Jan 22, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    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!
     
  12. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,807
    Likes Received:
    667
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    The name entry should be:

    Code:
    _service._tcp.test20
    Thank you.
     
    vb543 likes this.
  13. vb543

    vb543 Member

    Joined:
    Jan 22, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thought I tried that... At least it's working now!

    Thanks again for all of your help! I really appreciate it! :)
     
Loading...

Share This Page