MrLeN

Active Member
Dec 12, 2010
38
0
56
YAY!

*Falls off chair*

It worked!

Here's the code:

Code:
<?php

/*
 * =====SETUP =====
 */

// Import the xmlapi client class
//  - reference where you have the xmlapi.php class on you server
include_once "inc/xmlapi.php"; //yes I have it in the inc folder!

// Define the variables necessary for the class object to connect and
//  authenticate with the cPanel & WHM server
$ip = 'localhost';
$root_pass = 'fordtires';
$new_user_to_create = "teasugar";
$password_for_new_user = "5tag35sg35sdg";
$domain_owned_by_new_user = "teasugar.banana.com";

// Instantiate the PHP object from the xmlapi class
//  - At minimum, it requires that a server address is provided at instantiation
$xmlapi = new xmlapi($ip);

// Tell the object how you want to authenticate
//  - The password_auth() function is used for user/password authentication
//  - Alternatively, you can use hash_auth() if you have the remote access hash key
$xmlapi->password_auth("root",$root_pass);

// For testing, turn on debugging
// - there's a couple of long threads in the forum about how your PHP error reporting
//   settings can affect the presentation of the generated output
$xmlapi->set_debug(1);


/*
 * ===== MAIN WORK =====
 */

// Prepare dynamic data
$acct = array(
 'username' => $new_user_to_create,
 'password' => $password_for_new_user,
 'domain'   => $domain_owned_by_new_user
);

// Make the new account using the object's createacct() method
$result = $xmlapi->createacct($acct);

/*
 * ===== OTHER WORK =====
 */

//...do error checking of the result, render a success/fail response to the browser, etc... 
echo "Ok, now I am gonna look in WHM to see if the account was created!";
exit;
I am E XTREMELY happy now!

My website will be launched in a couple of hours now that I have this working.

Thanks heaps cPanelDavidN :)

Just one more question...

...how can I add a package?
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
Answer: It's not possible.

*as I come to find out after trying to add the functionality all day*

So, even though I have all this working now, I can't use it - because if I can't select a package, there's no point creating the account.

So, I am back to square 1: Loooking for a functional script that allows me to create WHM accounts (and set the package in the process), via PHP.

I have two courses of action at this point:

1). See if I can find a script that will allow me to modify the package, and paste it into my script after the package has been created. But I think that will give me a bad case of deja vu. I am already suffering from PTSD from trying to find a script that allows me to create the account in the first place.

2). I can let it set up the default account, and manually modify the package after people have made an order. However, this would be rather confusing for the customer if they see that they have unlimited space and transfer, and then it was taken away.

Any help will be appreciated. I am not far away from curling up into a corner of my house and crying myself to sleep, while rocking backwards and forwards.
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
If you want to specify a package when using the createacct() function of the Remote Api (aka XML/JSON API), then you must pass the value in the 'plan' parameter.

So, going from the previous example, make a change similar to this:
PHP:
// Prepare dynamic data
$acct = array(
    'username' => $new_user_to_create,
    'password' => $password_for_new_user,
    'domain'   => $domain_owned_by_new_user,
    'plan'     => $package_user_will_inherit_limits_from
);
Regards,
-David

P.S. The 'plan' parameter is different than the 'pkgname'. When 'savepkg' is set to '1', then the limits established for the new user will be used as a template for a new package; the value of 'pkgname' will be used as the name for the new package. I'm pretty certain in your case you do not need 'savepkg' or its friend 'pkgname', since you haven't mentioned package creation...just section (which is what 'plan' is for).
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
Just to clarify, you would replace the previous $acct = array( ... ); stuff in your previously functional script... with what DavidN recommends. If you can't get this working despite things working, please let us know.
 

MrLeN

Active Member
Dec 12, 2010
38
0
56
wow, finally, it works!

Also, I just got my website approved by AlertPay to accept credit cards, so looks like I will be able to launch my website today :)

I went to bed at 12:00am and I didn't sleep very well. I got back up at 5:00am just to see what the progress was, and when I checked AlertPay approved my site and this thread was answered. So, I am gonna stay up and finish my site now :)

I just have one more question.

If I want to add the customer email to the account, what is the paramater for that?

Also, thanks HEAPS for helping me! I would {{{never}}} work it out all by myself. But I also would have never given up, either. I would have just went crazy after failing for weeks :D
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
MrLeN,

The last link you posted is for the Standarized Hook System, not for the Remote API. They are two different things. You can find the available Remote API calls (used for things like creating, modifying, or removing accounts) here:
Remote API Documentation (XML and JSON APIs)

Under the "Functions" section on that page, you'll see that we have organized the different API calls into logical groups for you convenience: such as "Account Functions" section that contain stuff related to WHM accounts, and "Reseller Functions" section for administrating your reseller accounts, etc.

Specifically, you should look at the previous link I posted, for the createacct function:
Remote API Reference: Create Account (createacct)

Under the "Input" section on that page, you will find all the available parameters for createacct()

Regards,
-DavidN
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
How To get All the list of email accounts from cpanel through phpscript. . . . .

Examples/api2_example.php does this over at https://github.com/CpanelInc/xmlapi-php - just be sure to download the PHP class and put that file in Examples/api2_example.php and set your settings in api2_example.php before running on your cPanel &WHM server.
 

glenn0

Well-Known Member
Jul 23, 2012
67
2
8
cPanel Access Level
Website Owner
A great thread that's so close to answering a problem I have.

I have just purchased some domains in bulk and would like to add them to my WHM account giving each it's own cPanel account. Is there a script available (or anybody who can help for a price) that I can enter my WHM details in and a list of domains and have each account created with a random username and password at all? Ideally it wouldn't be WHM account specific as I have numerous WHM accounts and I would like to share the domains across each one.

Thanks for any help in pointing me to such a script, or indeed if one can be made for me for a price.

Thank you.