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.

Changing Email Password through API

Discussion in 'cPanel Developers' started by iSofia, Jun 3, 2014.

  1. iSofia

    iSofia Member

    Joined:
    Jun 3, 2014
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hello everyone. Sorry to ask this question again, but I was not allowed to bump an old thread with the same question.

    I came across a post from David Neimeyer (linked here), on changing the password of email accounts.

    This is what I came up with:
    Code:
    //host domain:     xyz.com
    //cpanel username: xyzusa
    //cpanel password: locknkey
    //email account:   john@abc.com
    //new password:    js123456
    
    include("xmlapi.php"); 
    
    $ip = '50.90.180.220';   //should this be the IP address for xyz.com?
    $root_pass = 'locknkey'; 
    
    $account = "xyzusa"; 
    $email_account = "john"; 
    $email_domain = "abc.com"; 
    
    $xmlapi = new xmlapi($ip); 
    $xmlapi->set_port (2082);
    $xmlapi->password_auth("root", $root_pass); 
    
    $args = array('domain'=>$email_domain, 'email'=>$email_account, 'password'=>"js123456")); 
    
    $xmlapi->api2_query($account, "Email", "passwdpop", $args);
    I would really appreciate some help with these points:
    1. Where do I get the include file xmlapi.php?
    2. Is $IP the IP address for the host domain?
    3. Are my sample values in the proper fields?
    4. Is my overall syntax and structure correct?

    Thanking you all for your kind attention. Any help would be appreciated. :)
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    As far as the first question, I believe you are looking for:

    https://github.com/CpanelInc/xmlapi-php

    As for the remaining questions, you may want to provide more information about the script you are developing so that other users can assist you. For instance, it utilized on a local or remote machine?

    Thank you.
     
  3. iSofia

    iSofia Member

    Joined:
    Jun 3, 2014
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hi Michael, and thanks for the quick reply.

    This script is to be run on the host server itself, to try and initiate a password change for one of the email accounts (john@abc.com) hosted on the same server.

    Sometimes I get no output, and sometimes I get this error:
    {"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}

    Still stuck. :(
     
  4. iSofia

    iSofia Member

    Joined:
    Jun 3, 2014
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Problem solved! The code is perfect, except for this one oversight on my part:

    Code:
    $xmlapi->password_auth("root", $root_pass);
    I simply changed the string "root" to the actual cPanel username, which is "xyzusa" in the example.

    Thank you, David Neimeyer, for this great piece of code. :)
     
Loading...

Share This Page