Solved

cPanel / WHM Api example

Posted on 2010-09-04
8
2,746 Views
Last Modified: 2012-05-10
Can someone please help me with a working example to use the CPanel / WHM Api.

I would like to update the A record for a particular domain hosted in cPanel / WHM through API.

0
Comment
Question by:nainil
  • 4
  • 4
8 Comments
 
LVL 21

Expert Comment

by:Julian Matz
ID: 33604857
Hello,

Using the cPanel XML API can be as easy as making a call to:

https://example.com:2087/xml-api/editzonerecord?domain=example.com&Line=2&ttl=86400

This will return a result in XML format, eg:

<cpanelresult>
    <data>
        <result>0</result>
        <reason>Access denied</reason>
    </data>
</cpanelresult>

This result, for example would tell you that the command failed (result=0) because access was denied (reason="Access denied").

To make the API call, you can use any number of programming languages like PHP, Perl, ASP. My choice would be PHP, and I would use curl to make.

http://php.net/manual/en/book.curl.php

Another option would be to simply download an existing cPanel API PHP class and either use it as is or modify it to suit your exact needs. Here's an example:
http://www.phpclasses.org/package/3534-PHP-List-and-manage-details-of-cPanel-hosting-accounts.html

But what scripting language did you have in mind for this?
0
 

Author Comment

by:nainil
ID: 33605148
Thank you julianmatz. Sorry for the incomplete information.

I want to implement the same using PHP/MySQL.

The Class you suggested does all except the DNS. I will try to look at the same and try to get the DNS manipulation function. But, if someone can get me a working example for DNS manipulation.

Thanks.
0
 
LVL 21

Accepted Solution

by:
Julian Matz earned 500 total points
ID: 33607175
If you use the XML PHP API from cpanel.net, you'll be able to edit your DNS using the example below. Here's a link to the API:

http://sdk.cpanel.net/lib/xmlapi/php/cp_xmlapi_php_v1.0.6.tar.gz
<?php

include("../xmlapi.php");

$ip = getenv('REMOTE_HOST');
$root_pass = getenv('REMOTE_PASSWORD');

$xmlapi = new xmlapi($ip);
$xmlapi->password_auth("root",$root_pass);

$xmlapi->set_debug(1);

$zone = 'example.com';
$Line = '1';

$args = array(
		  'address'=>'123.456.789.10',
		  'class'=>'IN',
		  'type'=>'A',
		  'ttl'=>'86400'
	);


print $xmlapi->editzonerecord($zone,$Line,$args);

?>

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:nainil
ID: 33608128
This is an incredible find. Thank you.

I am using the original file and examples. however, on Windows 7, (using WAMP), I get the following error:

Warning: file_get_contents(https://localcpanel.com/xml-api/listaccts) [function.file-get-contents]: failed to open stream: Invalid argument in C:\wamp\www\xmlapi.php on line 731

Any idea how to fix the same?
0
 

Author Comment

by:nainil
ID: 33608129
Also, the code works fine on Linux. So this is a Windows only issue apparently.
0
 
LVL 21

Expert Comment

by:Julian Matz
ID: 33608877
I'm not a Windows expert, but I think the error may have something to do with the SSL encryption (https). See if you can get these two DLLs from the PHP5 distribution:

libeay32.dll
ssleay32.dll
0
 

Author Comment

by:nainil
ID: 33614577
Just found that I did not have Curl setup. It worked fine once I worked on that piece. Thank you.
0
 
LVL 21

Expert Comment

by:Julian Matz
ID: 33619304
Glad I was able to help. Good luck with your API!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question