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!

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:
    24
    Likes Received:
    2
    Trophy Points:
    3
    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 Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,400
    Likes Received:
    1,952
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Andy M-B

    Andy M-B Member

    Joined:
    Jul 30, 2013
    Messages:
    10
    Likes Received:
    1
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi Michael, I see that xmlapi-php hasn't been updated in four years: Is it still current? Thanks.
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,400
    Likes Received:
    1,952
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @Andy M-B,

    While that class may still work, it's a good idea to use JSON instead of the XML-like output of our APIs when developing a script. See the following quote from our March 2017 Development Update Blog:

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice