The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Deleting email account with XML api

Discussion in 'cPanel Developers' started by bwor, Oct 21, 2010.

  1. bwor

    bwor Member

    Joined:
    Jun 15, 2008
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    How I can delete email account with XML api ?
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi bwor,

    To delete an email account using the XML-API, you need to actually use the Email::delpop API2 module, like so:

    Code:
    // I've placed like breaks for readability
    URL: https://10.1.1.1:2087/xml-api/cpanel?
    domain=somedomain.com&
    email=emailusername&
    cpanel_xmlapi_user=someuser&
    cpanel_xmlapi_module=Email&
    cpanel_xmlapi_func=delpop&
    cpanel_xmlapi_apiversion=2
    
    If you're coding with the PHP client class, your code would look something like this:
    PHP:

    include("xmlapi.php");

    $ip '10.1.1.1';
    $root_pass 'secret';

    $account "someuser";
    $email_account "emailusername";
    $email_domain "somedomain.com";

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);
    //$xmlapi->set_debug(1);

    $args = array(
      
    'domain'=>$email_domain
      
    'email'=>$email_account
    );

    $xmlapi->api2_query($account"Email""delpop"$args);
    If you're authenticating as the cPanel user, make sure and use port 2083/2082 instead of 2087/2086.

    You can find the documentation about invoking cPanel API1/API2 call via the XML-API here, CallingAPIFunctions < AllDocumentation/AutomationIntegration < TWiki

    Best Regards,
    -DavidN
     
  3. deepoint

    deepoint Registered

    Joined:
    Jan 19, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    hello :

    i use your script the delete email account but it's fail, and i don't know why?

    this is my code :
    PHP:

    <?
    include("xmlapi.php"); 

    $ip = "localhost";
    $root_pass = 'mypassord'; /// cpanel password 
    $account = "mayaccount";  /// cpanel username

    $email_account = "may_email_account"; /// email account name without @mydomain.com
    $email_domain = "mydomain.com"; /// without https:// 

    $xmlapi = new xmlapi($ip); 
    $xmlapi->password_auth("root",$root_pass);  //// for what this "root" is it password for anything????
    //$xmlapi->set_debug(1); 

    $args = array( 
      'domain'=>$email_domain,  
      'email'=>$email_account 
    ); 

    $xmlapi->api2_query($account, "Email", "delpop", $args);  

    ?>

    that's mycode so please can you help me.

    thank you
     
    #3 deepoint, Jan 19, 2011
    Last edited: Jan 19, 2011
  4. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi deepoint,

    I think your problem might have to do with authentication. Since you didn't provide any debugging or logging information, I can only guess based on the code and code comments in your sample script.

    When you call the password_auth() method, you should supply a valid, matching set of credentials. If you have root access, you can provide "root" as the first argument and the root password as the second argument. If you don't have root access, but merely your cPanel credentials, then you'll need to do two things: 1) change the arguments for the password_auth() method to be your cPanel username as the first argument and your cPanel password as the second argument. 2) you'll need to change the port. By default the xmlapi PHP object will use 2087. So, you'll need to add a call to the set_port() method, supplying the cPanel port you want to use (either 2083 or 2082).

    So, this is what I think you might try, if you don't have the root user's password

    PHP:
    include "xmlapi.php";

    $ip 'localhost';
    $account_pass 'mypassword'// cpanel password
    $account 'myaccount';  // cpanel username

    $email_account 'my_email_account'// email account name without @mydomain.com
    $email_domain 'mydomain.com'// domain associated with the email account

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($account$account_pass);
    $xmlapi->set_port(2083);
    //$xmlapi->set_debug(1);  // uncomment for debugging

    $args = array(
        
    'domain' => $email_domain,
        
    'email' => $email_account,
    );  

    $xmlapi->api2_query($account'Email''delpop'$args);

    If you are still having problems, please uncomment the debugging line and include the response message with your post.

    Best Regards,
    -DavidN
     
Loading...

Share This Page