≡ Menu

Parking and UnParking a domain with the cPanel API

I was trying to automate the process of creating parked domains on a cPanel server today and found myself playing around with Park module of the cPanel API via the amazing cPanel-XML-API-PHP.

This code was really simple and effective in parking a domain

<!--?php
//Do a little setup...
$serverIP = '<IP of cPanel server-->';
$user = '';
$hash = '';
$cPaneluser = '';
$domain = '';
 
//Make sure we load the PHP Client Library for cPanel's XMLAPI
require_once('cPanel-XML-API-PHP/xmlapi.php');
 
// Create an instance of the XMLAPI, and Authenticate using our username and hash
$xmlapi = new xmlapi('$serverIP');
$xmlapi->hash_auth($user, $hash);
 
//Send park request
$xmlapi->park($cPaneluser, $domain, '');
?>

Things were moving along smoothly until I attempted to unpark a domain via the cPanel API. I got an error when trying to unpark the domain:

"Error from park wrapper: Sorry, you do not control the domain"

After reading the API1 and API2 documentation for the park method and checking out xmlapi.php, I realized it was just a minor bug in how the API was being called by the unpark() function. The function that prepares the call for API2, api2_query(), expects an associative array; while the function prepping for API1, api1_query(), does not and unpark was sending an associative array to api1_query(). After making a minor change to the unpark() function on line 2076 of xmlapi.php from

 return $this->api1_query($username, 'Park', 'unpark', $args);

to

 return $this->api2_query($username, 'Park', 'unpark', $args);

I was able to successfully unpark a domain with this code.

<!--?php
//Do a little setup...
$serverIP = '<IP of cPanel server-->';
$user = '';
$hash = '';
$cPaneluser = '';
$domain = '';
 
//Make sure we load the PHP Client Library for cPanel's XMLAPI
require_once('cPanel-XML-API-PHP/xmlapi.php');
 
// Create an instance of the XMLAPI, and Authenticate using our username and hash
$xmlapi = new xmlapi('$serverIP');
$xmlapi->hash_auth($user, $hash);
 
//Send park request
$xmlapi->unpark($cPaneluser, $domain, '');
?>

I forked the project on github and committed my minor change; however, I’m not certain if MattDees is activly maintaining the project on github 🙁

If this helped you, let me know with a quick comment!

Comments on this entry are closed.

  • MattDees March 17, 2011, 10:56 am

    Oops, sorry about that!

    We are actively maintaining the project – but we’ve moved the repo off of my personal account over to https://github.com/CpanelInc/xmlapi-php

  • Gregg August 28, 2013, 6:31 am

    Thanks for sharing this code. Huge time saver. Cheers.

  • Mohi Sanisel May 6, 2014, 10:59 am

    Thanks man… you’re a life saver 😉