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.

Create cPanel account WHM API

Discussion in 'cPanel Developers' started by Pelsedu, Aug 20, 2016.

  1. Pelsedu

    Pelsedu Registered

    Joined:
    Aug 20, 2016
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Poland
    cPanel Access Level:
    Root Administrator
    I have problem with this code, it works, but website is locked, and don't return any information, then it's reloaded, and return that account exists, i can't handle this problem, other api calls works fine.

    Code:
    
    require __DIR__ . '/config.php';
    
    $data = [
    'username' => 'samplexxx',
    'domain'   => 'samplexxx.samplexxx.samplexxx',
    'password' => 'samplexxx'
    ];
    
    $query = 'https://samplexxx.samplexxx.net:2087/json-api/createacct?api.version=1';
    
    foreach ( $data as $k => $v ) {
    $query .= '&' . $k . '=' . $v;
    }
    
    $whmusername = 'root';
    
    $hash = $access_key;
    
    $curl = curl_init();
    curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 0 );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0 );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
    
    $header[ 0 ] = "Authorization: WHM $whmusername:" . preg_replace( "'(\r|\n)'", '', $hash );
    curl_setopt( $curl, CURLOPT_HTTPHEADER, $header );
    curl_setopt( $curl, CURLOPT_URL, $query );
    
    $result = curl_exec( $curl );
    if ( $result == false ) {
    error_log( "curl_exec threw error \"" . curl_error( $curl ) . "\" for $query" );
    }
    curl_close( $curl );
    
    print $result;
    
    
     
    #1 Pelsedu, Aug 20, 2016
    Last edited by a moderator: Aug 20, 2016
  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,

    Could you provide some additional details, including full error messages, on the steps you are taking to reproduce this issue? Can you reproduce the problem when using the command line example on the WHM API 1 Functions - createacct document?

    Thank you.
     
  3. Pelsedu

    Pelsedu Registered

    Joined:
    Aug 20, 2016
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Poland
    cPanel Access Level:
    Root Administrator
    I add file from console log, same info i can receive from php, but only with saving output to file, but server doesn't response anything, i got this response from browser, with other calls, i got very fast response, and can see result on browser.

    The {domain} page isn’t working
    {domain} didn’t send any data.

    ERR_EMPTY_RESPONSE
     

    Attached Files:

  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    I'm not sure I understand the issue. Could you let us know the step-by-step instructions we can take to reproduce this problem?

    Thank you.
     
  5. Pelsedu

    Pelsedu Registered

    Joined:
    Aug 20, 2016
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Poland
    cPanel Access Level:
    Root Administrator
    I want to use function echo, or print, to display information API sent back, but server doesn't respond. I got only error from browser "ERR_EMPTY_RESPONSE". It's like creating cPanel account disables server PHP output to WWW server (Apache). I can save response to file, but i can't send response to browser. I need to let know user that created the account that account is created, he needs to get that information.
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Could you let us know of any output to /usr/local/cpanel/logs/error_log or /usr/local/apache/logs/error_log when this happens? Also, could you try using the JSON or XML API examples from https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+createacct in a browser and let us know if the issue persists? This should help to verify if the issue is related to your custom script.

    Thank you.
     
  7. Pelsedu

    Pelsedu Registered

    Joined:
    Aug 20, 2016
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Poland
    cPanel Access Level:
    Root Administrator
    I looked over in the logs for information about this problem, but i found nothing. I think problem may be caused by function new profile - during that, as i know, the apache is restarted (right?), so PHP script will stop, i may be wrong, but i can't find solution...
     
  8. Stonex

    Stonex Registered

    Joined:
    Aug 30, 2016
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    làm bằng đại học
    cPanel Access Level:
    Website Owner
    I also have problems when manipulating cpanel, so PHP script will stop, i may be wrong can restart??
     
  9. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Feel free to open a support ticket using the link in my signature so we can take a closer look. You can post the ticket number here so we can update this thread with the outcome.

    Thank you.
     
Loading...

Share This Page