Community Forums
Connect with us on LinkedIn
Closed Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    Default Problem with CURL in XML api

    hi all
    i used this code for access cpanel but get nothing !
    please help me
    PHP Code:
    <?
    $cpanelusername 
    "xxx";
    $cpanelpassword "000";

    $query 
    "http://domain.com:2082/xml-api/cpanel?user=xxx&xmlin=<cpanelaction>
    <module>Ftp</module>
    <func>addftp</func>
    <apiversion>1</apiversion>
    <args>test</args>
    <args>123456</args>
    <args>/</args>
    <args>100</args>
    </cpanelaction>"
    ;


    $curl curl_init();        
    curl_setopt($curlCURLOPT_SSL_VERIFYPEER,0);    
    curl_setopt($curlCURLOPT_SSL_VERIFYHOST,0);     
    curl_setopt($curlCURLOPT_HEADER,0);            
    curl_setopt($curlCURLOPT_RETURNTRANSFER,1);    
    $header[0] = "Authorization: Basic " base64_encode($cpanelusername.":".$cpanelpassword) . "\n\r";
    curl_setopt($curlCURLOPT_HTTPHEADER$header);  
    curl_setopt($curlCURLOPT_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;
    ?>

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

    Default

    Hi amirem,

    You have a could of things that need correction. First, I would like to suggest you look at our PHP client class http://sdk.cpanel.net/lib/xmlapi/php..._v1.0.6.tar.gz

    It has all the cURL code that you'll need. So, you could copy that code. But better, you can just include the class file and spawn an object instance. Here's an example of how to add an ftp user using out PHP class

    PHP Code:
    <?php
    include("xmlapi.php");

    $ip "domain.com";
    $user_name "myuser";
    $user_pass "secret1";

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($user_name$user_pass);
    $xmlapi->set_port('2083');
    //$xmlapi->set_debug(1);

    $module 'Ftp';
    $function 'addftp';
    $args = array(
      
    'user' => 'testftpuser',
      
    'pass' => 'testpass',
      
    'quota' => 0
      
    'homdir' => '/',
    );

    $result_obj $xmlapi->api2_query($user_name$module$function$args);
    ?>
    uncommiting the debug method, will give you more info when you execute it. For example, it will provide you the URL that it's using:
    Code:
    URL: https://domain.com:2083/xml-api/cpanel
    DATA: user=testftpuser&pass=testpass&quota=0&homdir=%2F&cpanel_xmlapi_user=myuser&cpanel_xmlapi_module=Ftp&cpanel_xmlapi_func=addftp&cpanel_xmlapi_apiversion=2
    So, other things that you've got going on, besides the cURL issue:

    1) You should use API2 call over API1 calls if possible. There's only a few modules that are available for both; 'Ftp' is one of them

    2) If you are making XML-API calls, it's best to use the "fast mode" construction for the URL arguments. Examples are here: CallingAPIFunctions < AllDocumentation/AutomationIntegration < TWiki . We currently support both, but it's a lot faster and easier to use "fast mode".

    Best 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

  3. #3
    Member
    Join Date
    Aug 2010
    Posts
    8

    Default Re: Problem with CURL in XML api

    Hi there,

    I am using the xml-api. Recently i am experiencing problems creating accounts.
    Using fsockopen -> it creates the account but the code breaks therefore i dont receive any response.
    Using CURL -> it looks more promissing - account get created but the response returned is "sorry group already exist ..."

    Confusion comes when i try the same code on my localhost (xampp) and it runs perfectly and response is also returned.

    Does anybody might have encountered that or have a sol please.
    I am on the fourth day of sorting it out and still dont understand how and why it happens.

    Thanks a lot for any help,

    Regards
    Last edited by jerome.chevreau; 04-07-2011 at 02:49 AM.

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

    Default Re: Problem with CURL in XML api

    Hi Jerome,

    What port are you using? do you have OpenSSL support for the PHP binary (not in your xampp environment, but the one the first one you mention). Most of the time, fopen stuff fails due to a request over https and OpenSSL in not compiled in.

    Are you using the XML-API client class? I ask because it usesfopen() and not fsockopen(). IIRC, you should be able to use fsockopen(). But typically, unless I need a particular socket type, I just use context streams with fopen()...just an opinion.

    If you get back an error, like "sorry already exists..." there should be no account created in cPanel/WHM. That type of error signals a failure in the creation process. Please confirm that the account wasn't previously there.

    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

Similar Threads & Tags
Similar threads

  1. Xml api creatacc problem - server response break
    By jerome.chevreau in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 04-05-2011, 02:10 AM
  2. problem with xml-api/modifyacct & twiki
    By DavidS in forum cPanel Developers
    Replies: 2
    Last Post: 11-21-2009, 02:13 PM
  3. xml api problem
    By hellomoto in forum cPanel Developers
    Replies: 3
    Last Post: 05-22-2008, 10:20 PM
  4. Problem whith XML API accountsummary
    By eugui in forum cPanel Developers
    Replies: 2
    Last Post: 02-13-2008, 07:46 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube