cPanel / WHM Api example

Posted on 2010-09-04
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.

Question by:nainil
  • 4
  • 4
LVL 21

Expert Comment

by:Julian Matz
ID: 33604857

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

This will return a result in XML format, eg:

        <reason>Access denied</reason>

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.

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:

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

Author Comment

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.

LVL 21

Accepted Solution

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


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

$xmlapi = new xmlapi($ip);


$zone = '';
$Line = '1';

$args = array(

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


Open in new window


Author Comment

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( [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?
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.


Author Comment

ID: 33608129
Also, the code works fine on Linux. So this is a Windows only issue apparently.
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:


Author Comment

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

Expert Comment

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

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

937 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now