Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    2

    Default Getting started

    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. #2
    cPanel Staff cPanelJared's Avatar
    Join Date
    Feb 2010
    Location
    Houston, TX
    Posts
    1,066

    Default Friendly moderator note

    I have moved this thread to our Developer Discussions section.
    For hands-on assistance, please reference our new support information page: Where should I go for support?
    cPResources: Support Options - Submit a ticket here - Additional Support Options - Forums Search - Mailing Lists(Alt) - Documentation


    -- Jared Ryan, Technical Analyst, cPanel Technical Support

  3. #3
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default Re: Getting started

    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
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    2

    Default Re: Getting started

    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

Similar Threads & Tags
Similar threads

  1. Geting Started
    By jghogue in forum New User Questions
    Replies: 3
    Last Post: 05-02-2011, 08:54 AM
  2. Getting started
    By elodie in forum New User Questions
    Replies: 0
    Last Post: 04-19-2011, 09:26 PM
  3. Getting Started
    By drshelm2001 in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 03-21-2004, 04:37 PM
  4. Getting Started...
    By ugroup.net in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 01-08-2003, 06:23 PM
  5. httpd could not be started ?!
    By BensonEdge in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 08-28-2002, 01:10 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube