bwor

Member
Jun 15, 2008
20
0
51
I have cpanel version 11 and i try to auto create email from PHP using this code

<?php
$cpuser = "cpanel_user_name";
$cppass = "cpanel_password";
$euser = "email_user_name";
$epass = "email_password";
$equota = "email_quota";
$domain = "domian.com";
$url = "http://".$cpuser.":".$cppass."@".$domain."2082/frontend/x3/mail/doaddpop.html?email=".$euser."&domain=".$domain."&password=".$epass."&quota=".$equota;
if($cpanel = fopen($url, "r"))
{
echo "Success email creation.";
fclose($cpanel);
}
else
{
echo "Failed email creation.";
}
?>

When I run this code I get the result "Success email creation." but when I login to cpanel I not found the new email in the list.

What the wrong ?
 

nelwa

Member
Jul 21, 2008
7
1
53
South Africa
I have cPanel version 11.24.5 and I can confirm that I have almost exactly the same problem. I run my script, which returns this array:

Code:
array(3) {
  ["apiversion"]=>
  string(1) "2"
  ["func"]=>
  string(6) "addpop"
  ["module"]=>
  string(5) "Email"
but when I login on cpanel, the email address isn't shown...this is driving me mad...

I run the instruction with an api2 query like this:
PHP:
$arr = $xmlapi->api2_query($account, "Email", "addpop", array(domain=>$res['domain'], email=>$email1, password=>$password1, quota=>0) );
var_dump($arr);
I know I'm authenticating correctly, because I can list bandwidth usage, etc. without any problems...

This is an urgent problem and any help would be greatly appreciated.
 

rjf1505

Member
Apr 16, 2005
8
0
151
Same here

Hi,

I also use a script to create email and other stuff.
All works fine exept the email part.

Anyone got news from Cpanel ?

Thanks
Robert-Jan
 

cPanelDavidN

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

Hi guys,

Using the XMLAPI.php class, you should be about to add pop emails to an account like so:
Code:
$username = 'dave'; //cpanel username associated with our domain
$newpopdata = array(
 'domain'=>'dave.com',
 'email'=>'mr_dave',
 'password'=>'my_s3cr3t_pop!passwd',
 'quota'=>0,
);
$result = $xmlapi->api2_query($username, "Email", "addpop", $newpopdata);
This is the same as nelwa's code. The main difference is I'm quoting my array keys; not fatal, but depending it may affect your code.

I know for certain that his works on 11.25.0. However, I will try on an 11.24.5 server later and will post my findings.

Regards,
-Dave
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
api call to add pop

Hi guys,

Unfortunately, the documentation isn't crystal clear on api2 calls via URL. Short answer: not all api2 calls are supported in 11.24.5. All api1 calls are. Use an api1 like the following example for 11.24.5:
Code:
$account = "dave";
$email_user = "mr_dave";
$email_password = "my_s3cr3t_pop!passwd";
$email_domain = "dave.com";
$email_quota = '0';

$xmlapi = new xmlapi($ip);
$xmlapi->password_auth("root",$root_pass);
$xmlapi->set_output('xml');

$result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
The actual url query string would look like:
Code:
https://10.1.5.162:2087/xml-api/cpanel?user=dave&cpanel_xmlapi_module=Email&cpanel_xmlapi_func=addpop&cpanel_xmlapi_apiversion=1&arg-0=mr_dave&arg-1=my_s3cr3t_pop!passwd&arg-2=0&arg-3=dave.com
 

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
Houston, TX
cPanel Access Level
Root Administrator
More clarification:

The API2 documentation was targetted @ 11.25.0. At the time we started developing it we decided that it was less of a time sync to target the release that would be coming out shortly.

I apologize for the confusion.
 

bwor

Member
Jun 15, 2008
20
0
51
Hi guys,

Unfortunately, the documentation isn't crystal clear on api2 calls via URL. Short answer: not all api2 calls are supported in 11.24.5. All api1 calls are. Use an api1 like the following example for 11.24.5:
Code:
$account = "dave";
$email_user = "mr_dave";
$email_password = "my_s3cr3t_pop!passwd";
$email_domain = "dave.com";
$email_quota = '0';

$xmlapi = new xmlapi($ip);
$xmlapi->password_auth("root",$root_pass);
$xmlapi->set_output('xml');

$result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
The actual url query string would look like:
Code:
https://10.1.5.162:2087/xml-api/cpanel?user=dave&cpanel_xmlapi_module=Email&cpanel_xmlapi_func=addpop&cpanel_xmlapi_apiversion=1&arg-0=mr_dave&arg-1=my_s3cr3t_pop!passwd&arg-2=0&arg-3=dave.com
I think the previous code using with WHM account only but in my status I have only cpanel account.
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
You can authenticate with your user credentials and as long as you're only requesting action for your account, it should succeed.

Code:
$account = "dave";
$account_pass = "d4v3sSecret!";

$email_user = "mr_dave";
$email_password = "my_s3cr3t_pop!passwd";
$email_domain = "dave.com";
$email_quota = '0';

$xmlapi = new xmlapi($ip);
$xmlapi->password_auth($account, $account_pass);  <-- USE USER ACCOUNT AUTH
$xmlapi->set_output('xml');

$result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
 

bwor

Member
Jun 15, 2008
20
0
51
You can authenticate with your user credentials and as long as you're only requesting action for your account, it should succeed.

Code:
$account = "dave";
$account_pass = "d4v3sSecret!";

$email_user = "mr_dave";
$email_password = "my_s3cr3t_pop!passwd";
$email_domain = "dave.com";
$email_quota = '0';

$xmlapi = new xmlapi($ip);
$xmlapi->password_auth($account, $account_pass);  <-- USE USER ACCOUNT AUTH
$xmlapi->set_output('xml');

$result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
I get an error when I execute this code
(HTTP 500 Internal Server Error)
The website cannot display the page
HTTP 500
Most likely causes:
•The website is under maintenance.
•The website has a programming error.

What you can try:
Refresh the page.

Go back to the previous page.

More information

This error (HTTP 500 Internal Server Error) means that the website you are visiting had a server problem which prevented the webpage from displaying.

For more information about HTTP errors, see Help.
 

bwor

Member
Jun 15, 2008
20
0
51
You can authenticate with your user credentials and as long as you're only requesting action for your account, it should succeed.

Code:
$account = "dave";
$account_pass = "d4v3sSecret!";

$email_user = "mr_dave";
$email_password = "my_s3cr3t_pop!passwd";
$email_domain = "dave.com";
$email_quota = '0';

$xmlapi = new xmlapi($ip);
$xmlapi->password_auth($account, $account_pass);  <-- USE USER ACCOUNT AUTH
$xmlapi->set_output('xml');

$result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
cPanelDavidN what is $ip ? I what the value of $ip here ?
 
Last edited:

bwor

Member
Jun 15, 2008
20
0
51
You can authenticate with your user credentials and as long as you're only requesting action for your account, it should succeed.

Code:
$account = "dave";
$account_pass = "d4v3sSecret!";

$email_user = "mr_dave";
$email_password = "my_s3cr3t_pop!passwd";
$email_domain = "dave.com";
$email_quota = '0';

$xmlapi = new xmlapi($ip);
$xmlapi->password_auth($account, $account_pass);  <-- USE USER ACCOUNT AUTH
$xmlapi->set_output('xml');

$result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
You can check the output of execution this code from this link
2shared - download Error_01.jpg
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
$ip is a variable containing the IP address of the server. You could also use you domain name. You must populate this with your own information.

The xmlapi object must have the address (IP or domain) to know where to send the requests.

If you don't have the right web address, then I'd expected to see the 500 errors you're getting. Try putting in your domain name and see what you get.

Regards,
-DavidN
 

bwor

Member
Jun 15, 2008
20
0
51
$ip is a variable containing the IP address of the server. You could also use you domain name. You must populate this with your own information.

The xmlapi object must have the address (IP or domain) to know where to send the requests.

If you don't have the right web address, then I'd expected to see the 500 errors you're getting. Try putting in your domain name and see what you get.

Regards,
-DavidN
I checked the error_log file and I get this result after execution your code
PHP:
[15-Jun-2010 15:52:59] PHP Fatal error:  Class 'xmlapi' not found in /home/xxxx/public_html/yyyy/test/test.php on line 13
What is that meaning ?
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
in your test.php, you need to include/require the xmlapi client class.
Code:
include('xmlapi.php');
you'll need to download the class from here http://sdk.cpanel.net/lib/xmlapi/php/cp_xmlapi_php_v1.0.5.tar.gz and extract it. Place "xmlapi.php" somewhere that's in you PHP include_path (or modify your include_path in test.php to include the directory where you placed "xmlapi.php").

the download also includes examples of how to use the class.

-DavidN
 

bwor

Member
Jun 15, 2008
20
0
51
in your test.php, you need to include/require the xmlapi client class.
Code:
include('xmlapi.php');
you'll need to download the class from here http://sdk.cpanel.net/lib/xmlapi/php/cp_xmlapi_php_v1.0.5.tar.gz and extract it. Place "xmlapi.php" somewhere that's in you PHP include_path (or modify your include_path in test.php to include the directory where you placed "xmlapi.php").

the download also includes examples of how to use the class.

-DavidN
Thanks alot and it's working now and I think you can close this thread.
 

toxic360

Registered
Sep 4, 2010
1
0
51
i have this error ! please help

Uncaught exception 'Exception' with message 'No host defined' in /home/xxxxx/public_html/test/xmlapi.php:205 Stack trace: #0 /home/xxxxx/public_html/test/test.php(11): xmlapi->__construct(NULL) #1 {main} thrown in /home/xxxxx/public_html/test/xmlapi.php on line 205
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
It means that you're script is trying to instantiate the xmlapi object without passing the IP address (or FQDN).

PHP:
<?php
include 'xmlapi.php';

$ip = 'my.website.com';

// you MUST pass the IP or hostname of the cPanel box
//  you're gonna send the requests to when you create
//  the xmlapi object.
$xmlapi_obj = new xmlapi($ip);

// do stuff...
-DavidN
 

lbeachmike

Well-Known Member
Dec 27, 2001
306
1
316
Long Beach, NY
cPanel Access Level
Root Administrator
Hi there -

I am still successfully using the older format in my scripts to provision email accounts, per the original poster's inquiry in this thread -

Code:
$url = "http://".$cpuser.":".$cppass."@".$domain."2082/frontend/x3/mail/doaddpop.html?email=".$euser."&domain=".$domain."&password=".$epass."&quota=".$equota;
Although the new API format appears as if it may be marginally simpler to work with, is there any reason that I need to consider migrating my code at any point?

Is the old format going to be supported indefinitely or is there any concern of its discontinuation?

Basically, what would be the reason to use the new API format over the old?

Thanks.

Mike
 

echogaurav

Registered
Feb 26, 2013
1
0
1
cPanel Access Level
Root Administrator
in your test.php, you need to include/require the xmlapi client class.
Code:
include('xmlapi.php');
you'll need to download the class from here http://sdk.cpanel.net/lib/xmlapi/php/cp_xmlapi_php_v1.0.5.tar.gz and extract it. Place "xmlapi.php" somewhere that's in you PHP include_path (or modify your include_path in test.php to include the directory where you placed "xmlapi.php").

the download also includes examples of how to use the class.

-DavidN
Please help me with my code. I have tried the steps that has been described but still no success. Please take a look at the code and see if anything i have missed! Follow is my code:-

<?php
include ("xmlapi.php"); // I have this file included and placed correctly

$account = "cpUsername"; // not real but i have deployed the correct one
$account_pass = "phpisechoing";

$email_user = "gaurav";
$email_password = "pwd4Gaurav";
$email_domain = "gauravsingh.com"; // not real but i have deployed the correct one
$email_quota = '0';

$xmlapi = new xmlapi('192.168.182.195'); // not real but i have deployed the correct one
$xmlapi->password_auth($account, $account_pass);
$xmlapi->set_output('xml');

echo $result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );

?>


The output i got is:-

Access denied 0 Access denied
 
Last edited: