Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

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.

Connecting to cPanel API from remote server

Discussion in 'cPanel Developers' started by Neutrall, Jul 25, 2017.

Tags:
  1. Neutrall

    Neutrall Member
    PartnerNOC

    Joined:
    Jul 22, 2014
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    DataCenter Provider
    Hi all,

    I would need some help on initiating a call to cPanel API from a remote server.

    I’ll need to access the API for getting a listing and modifying subdomains and reading and modifying a file on the hosting.

    Currently I have some problem on how to create the actual API call in PHP, this is what I have so far :

    Hi all,

    I would need some help on initiating a call to cPanel API from a remote server.

    I’ll need to access the API for getting a listing and modifying subdomains and reading and modifying a file on the hosting.

    Currently I have some problem on how to create the actual API call in PHP, this is what I have so far :

    Code:
    $user = "user";
    $pass = "password";
    // The URL
    $url = 'https://'.$user.':'.$pass'@mycpanel.com:2083/cpsess###########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=SubDomain&cpanel_jsonapi_func=listsubdomains&regex=domain';
    
    
    // Set the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $time);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    // Turn off the server and peer verification (TrustManager Concept).
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
     
    // Get response from the server.
    $resp = curl_exec($ch);
    
    // Unserialize data
    $res = unserialize($resp);
    
    Currently, I don’t understand with what I should change the “cpsess###########” with!

    Secondly, I’m not even sure I’m using the right authentication method!

    And Finally, I see that is I need to modify the content of one file, this need to be done with UAPI, but can I access UAPI from a remote server?

    Thank you!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,427
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page