Can I get an example of the API?

cronik

Registered
Jul 30, 2010
4
0
51
I read through the api documents, I'm fairly good with PHP. All though, I'm unsure on when a user enters a, Subdomain, an Email, a Username, a Password, I don't get how you send that information to cPanel and receive a message saying "Yeah! It was created!".

Can someone give me a PHP example of that? Maybe have a few text boxes in there for example? I'd really apprecaite it!

Peter
 

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
San Francisco, CA
cPanel Access Level
Root Administrator

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
if you're a PHP developer and you wanting to invoke cPanel API calls, you should consider using this PHP client class: https://github.com/CpanelInc/xmlapi-php . This is used for remote cPanel & WHM API calls. If you are developing a cPanel plugin, then you will use the LiveAPI for PHP client class (/usr/local/cpanel/php/cpanel.php on you cPanel box).

There are several threads about both class. If you have any specific question, let us know.

Regards,
-DavidN
 

cronik

Registered
Jul 30, 2010
4
0
51
if you're a PHP developer and you wanting to invoke cPanel API calls, you should consider using this PHP client class: https://github.com/CpanelInc/xmlapi-php . This is used for remote cPanel & WHM API calls. If you are developing a cPanel plugin, then you will use the LiveAPI for PHP client class (/usr/local/cpanel/php/cpanel.php on you cPanel box).

There are several threads about both class. If you have any specific question, let us know.

Regards,
-DavidN
Wow! That api really helped. The code I have is:
<?php
include_once "api.php" ;

$ip = getenv('REMOTE_HOST');
$root_pass = "hidden";

$xmlapi = new xmlapi('127.0.0.1');
$xmlapi->password_auth("root",$root_pass);

$xmlapi->set_debug(1);

$acct = array( username => "someuser", password => "pass123", domain => "thisdomain.com");
print $xmlapi->createacct($acct);

?>
All though, it doesn't print anything but it creates the account. I just want to know how I can print out to users saying, "Yes, your account was created"

EDIT: Even if I do listaccts() it doesn't display anything
 

cPanelDavidN

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

print $xmlapi->createacct($acct);
that likely won't work. (I think the examples that ship with xmlapi.php erroneously have that [I'll open a ticket to get that updated]). The default return from those query methods is a SimpleXML object, so, calling 'print' on an object is not meaningfull. You will need to traverse the the object to determine the state of action.

There are a couple of ways you can go about it.
1) change the output to 'array' with set_output() prior to the api call, and iterate that response
2) use the SimpleXML object's method interface (that should map the the nodes of the response)

In either case, depending on the exact function, you will want to evaluate the status node: "<status>$some_bool</status>". The Remote API function documentation should have examples of the expected output

Depending on how you have your PHP error settings, and how you PHP is getting executed, set_debug(1) may or may not render a copy of the response; once that is established correctly for your development environment, you can get an idea of what you're traversing. I suggest doing a forum/google search for xmlapi.php and display_errors(): Somewhere I've written a length post or two about that specific topic. (if you can't find it or are still having trouble, let me know)

Regards,
-DavidN