Reputation: 45
I am sorry if this request is in the wrong area.
I am learning to use PHP and the CPanel API. I've got the following code and it's giving me a stack error because I am missing something seemingly simple
$domain = array('username' => 'bobbie', 'domain' => 'bobbie.com', 'pass' => 'bobbie123');
$acct = $cp->whm_api('createacct', $domain);
echo "WHM Create: {$acct->createacct}\n";
I know I'm connecting to WHM properly because my code before this outputs the version of WHM correctly. The above code is giving me an error stating that createacct needs to be passed an array as the first parameter:
WHM Version: 11.54.0.21
PHP Fatal error: Uncaught exception 'Exception' with message 'createacct requires that first parameter passed to it is an array' in /root/whmrm/Cpanel/Service/XmlapiClientClass.php:146
Stack trace:
#0 [internal function]: Cpanel_Service_XmlapiClientClass->createacct('bobbie', 'bobbie.com', 'bobbie123')
#1 /root/whmrm/Cpanel/Service/WHM.php(195): call_user_func_array(Array, Array)
#2 [internal function]: Cpanel_Service_WHM->__call('createacct', Array)
#3 [internal function]: Cpanel_Service_WHM->createacct('bobbie', 'bobbie.com', 'bobbie123')
#4 /root/whmrm/Cpanel/PublicAPI.php(525): call_user_func_array(Array, Array)
#5 /root/whmrm/create_sites_on_server.php(68): Cpanel_PublicAPI->__call('whm_api', Array)
#6 /root/whmrm/create_sites_on_server.php(68): Cpanel_PublicAPI->whm_api('createacct', Array)
#7 {main}
thrown in /root/whmrm/Cpanel/Service/XmlapiClientClass.php on line 146
Line 3 of the output is showing that I'm not sending the data properly. Any help would be appreciated. I've googled and most of the results give me information about the xml_api and how to use that. Thanks for your assistance.
Upvotes: 3
Views: 339
Reputation: 69967
Looking at the source for the PublicAPI
class, it appears that if an array is given as the parameters, it only calls the resulting function passing the first element from the array (source).
I was able to create an account using this code:
$cp = Cpanel_PublicAPI::getInstance($config);
$whm = Cpanel_PublicAPI::factory('whm');
$domain = array(
'domain' => 'mydomain.com',
'username' => 'drewt2',
'password' => 'myp4ssw0rd!'
);
$response = $whm->createacct($domain);
You can see the functions and there parameters here: Cpanel_Service_XmlapiClientClass.
Unfortunately, the code hasn't been updated in 5 years, and the examples aren't that helpful so you'll likely have to look through the code to figure out most of what you'll want to do.
Upvotes: 2