• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3212
  • Last Modified:

cPanel / WHM Api example

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.

  • 4
  • 4
1 Solution
Julian MatzJoint ChairpersonCommented:

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?
nainilAuthor Commented:
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.

Julian MatzJoint ChairpersonCommented:
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:



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

$xmlapi = new xmlapi($ip);


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

$args = array(

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


Open in new window

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

nainilAuthor Commented:
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?
nainilAuthor Commented:
Also, the code works fine on Linux. So this is a Windows only issue apparently.
Julian MatzJoint ChairpersonCommented:
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:

nainilAuthor Commented:
Just found that I did not have Curl setup. It worked fine once I worked on that piece. Thank you.
Julian MatzJoint ChairpersonCommented:
Glad I was able to help. Good luck with your API!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now