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.

Getting started

Discussion in 'cPanel Developers' started by elodie, Apr 19, 2011.

  1. elodie

    elodie Registered

    Joined:
    Apr 19, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Hi, i am a complete newbie to this and i'm really struggling with how to get started.

    I want to be able to add databases, users and subdomains using php.

    I have had a look through the documentation for using the API and one of the first things it says to do is an authentication test, in php this looks like:

    Code:
    $whmusername = "username";
    $whmpassword = "password"
    
    $query = "https://127.0.0.1:2087/";
    
    $curl = curl_init();		
    # Create Curl Object
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);	
    # Allow self-signed certs
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0); 	
    # Allow certs that do not match the hostname
    curl_setopt($curl, CURLOPT_HEADER,0);			
    # Do not include header in output
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);	
    # Return contents of transfer on curl_exec
    $header[0] = "Authorization: Basic " . base64_encode($whmusername.":".$whmpassword) . "\n\r";
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);  
    # set the username and password
    curl_setopt($curl, CURLOPT_URL, $query);			
    # execute the query
    $result = curl_exec($curl);
    if ($result == false) {
    	error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");	
    # log error if curl exec fails
    }
    curl_close($curl);
    
    print $result;
    I have filled out the username, password and query fields and when i run the file i don't receive any response. What should the result print out if this has been sucessful? Also if not successful should i receive an error?

    One more thing do i need to download anything?

    sorry its such a basic question but i'm getting nowhere fast.

    Thanks,
    Rebecca
     
  2. cPanelJared

    cPanelJared Technical Analyst
    Staff Member

    Joined:
    Feb 25, 2010
    Messages:
    1,842
    Likes Received:
    18
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Friendly moderator note

    I have moved this thread to our Developer Discussions section.
     
  3. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi Rebecca,

    I suggest you use one the client classes instead of coding all the mechanics yourself. I've provided some links below. As far as not receiving any errors, if you coding in PHP, often types the error is not being directed to STDOUT/STDERR (or is being suppressed by an ini setting) and thus you don't see the error. The most common PHP culprit (eg, error) is that the PHP binary executing your script doesn't have cURL with SSL support or cURL at all. You could try using a non-ssl port or using the fopen functions (....all of which is easy/built into the PHP clients below)

    Perl:
    1) The PublicAPI client class
    - github repo
    - CPAN

    PHP:
    1) The PublicAPI client class (which is in BETA)
    - github repo
    - PEAR channel

    2) The XML-API client class, the precursor to the PHP PublicAPI (less sophisticated & very straightfoward)
    - github repo

    There are several posts in the developer discussions forum related to the PHP XML-API client class...the PublicAPI client classes are newer so there will be few threads...but we're here to answer any questions!

    Regards,
    -DavidN
     
  4. elodie

    elodie Registered

    Joined:
    Apr 19, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Hi Thanks for that information, i am just having a look through it now.

    Do i really need all of this if i only want to be adle to add a databse and a domain?

    Thanks
     
Loading...

Share This Page