Skip to main content

Unable to create email account via xml api

Comments

4 comments

  • cPanelMichael
    Hello :) Please check to ensure you have working resolvers configured for your system in the /etc/resolv.conf file. You can try using public resolvers (8.8.8.8 and 8.8.4.4) to see if the error message continues. Thank you.
    0
  • KostonConsulting
    Welcome to the forums. In the future, it would be quite helpful if you can post a code snippet along with the error messages. Since I don't know what's on line 237 of test_mail.php, I'll give you my best guess: Sounds like you are not passing the ip address of your cPanel/WHM server when creating an xmlapi object. I'd imagine your code looks like: $xmlapi = new xmlapi();
    where it should specify the IP, like so: $xmlapi = new xmlapi($ip);
    0
  • techahamed
    Thanks for the reply,koston and cpanel michael.That problem is solved by correcting host resolvers. Now i'am now getting a new error Fatal error: Uncaught exception 'Exception' with message 'curl_exec threw error "Unknown SSL protocol error in connection to ip number. Here is my xml api code for helping you find the problem require_once('api.php'); $ip = 'myip'; $xmlapi = new xmlapi($ip); $xmlapi->password_auth("myuser","mypass"); //the server login info for the user you want to create the emails under $xmlapi->set_output('json'); $params = array(domain=>'mbracecloud.com', email=>'hello', password=>'hello0513', quota=>250); //quota is in MB $addEmail = json_decode($xmlapi->api1_query("root", "Email", "addpop", $params), true); if($addEmail['cpanelresult">['data">[0]['result">){ echo "success"; } else { echo "Error creating email account:\n".$addEmail['cpanelresult">['data">[0]['reason">; } Techahamed
    0
  • KostonConsulting
    I've noticed that it seems (my assumption) like you are connecting as a cPanel user for password_auth() and then connecting as root for the query. That won't work. You can connect as root for password_auth() and then have $user set to a cPanel user for api1_query() but not the other way around. If you want to connect as the user for password_auth(), you should specify the cPanel port in your xmlapi object like so: $xmlapi->set_port('2083');
    and you need to specify the domain owner for any api1/api2 queries, regardless of which user you are using to authenticate: $xmlapi->api1_query($domain_owner, "Email", "addpop", $params)
    As far as the SSL error goes, this could be a number of things. The XMLAPI library is using curl to connect to your cPanel/WHM server and the response it is getting back is not what curl is expecting. You should test to see if you can connect via command line curl to your cPanel/WHM server (this should return some JSON with access denied): curl -k "https://hostname:2087/json-api/cpanel?user=username&cpanel_jsonapi_module=Email&cpanel_jsonapi_func=addpop&cpanel_jsonapi_version=2&domain=mbracecloud.com&email=hello&password=hello0513&quota=250"
    If you're not getting JSON back, then curl is having issues connecting to cPanel/WHM and you may have an invalid SSL cert, or ports 2083/2087 may be blocked, or you're connecting to a machine that isn't broadcasting SSL, or some other issue is preventing a SSL connection. Try connecting with openssl to see if you get any errors: openssl s_client -connect hostname:2087
    Also try curl's verbose mode on the headers: curl --verbose -i -k "https://hostname:2087/json-api/cpanel?user=username&cpanel_jsonapi_module=Email&cpanel_jsonapi_func=addpop&cpanel_jsonapi_version=2&domain=mbracecloud.com&email=hello&password=hello0513&quota=250"
    It should also be noted that in API1, you shouldn't pass the argument names in the params array. Instead, you just need to present the arguments as a properly ordered array of values like so: $params = array('hello','hello05013','250','mbracecloud.com'); //(email,password,quota,domain)
    Since it's easier to visually debug associative arrays (and because it's always best to use the newest API), you should use API2 rather than API1: $xmlapi->api2_query($domain_owner, "Email", "addpop", $params)
    0

Please sign in to leave a comment.