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.

Can't get api1_query() to work...

Discussion in 'cPanel Developers' started by cachilupi, Jul 28, 2009.

  1. cachilupi

    cachilupi Member

    Joined:
    Jul 24, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    I'm using the xmlapi.php.inc class provided here in the forums, but I'm unable to get any functions using api1_query() to work. Here's what I'm trying....

    PHP:
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root","*****");
    $xmlapi->set_port('2083');
    $xmlapi->return_object(1);
    $xmlapi->set_debug(1);

    print 
    $xmlapi->api1_query("webchuck""Park""park", array('whatever.com') );
    //--  OR  --//
    print $xmlapi->api1_query("webchuck""SubDomain""addsubdomain", array('test123','webchuckhosting.com',0,0,'/public_html') );
    I get the following object returned...
    Code:
    object(SimpleXMLElement)#7 (3) {
      ["apiversion"]=>
      string(1) "1"
      ["type"]=>
      string(4) "text"
      ["data"]=>
      object(SimpleXMLElement)#6 (2) {
        ["result"]=>
        string(1) "0"
        ["reason"]=>
        string(23) "No Valid Command Given."
      }
    }
    
    
    Any ideas would be greatly appreciated.

    Thanks,
    Chuck
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    You are attempting to login to the cPanel interface as root. This will not work. You should set your port to 2087 (WHM port) if you wish to authenticate as root rather than as that cPanel user.
     
  3. cachilupi

    cachilupi Member

    Joined:
    Jul 24, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    Actually, I've been logging in both as 'root' and as a cpanel account user, sorry if my posted code was misleading. I'm able to authenticate as root @ port:2087 and webchuck (cpanel username) @ port:2083.

    Any other thoughts?

    Thanks,
    Chuck
     
  4. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Both of these calls have API2 interfaces. It is always recommended to use the API2 interface when it is available.

    If you need the parameters for these API functions, I can get these for you tomorrow, please let me know via PM.
     
  5. cachilupi

    cachilupi Member

    Joined:
    Jul 24, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    API2 functions

    I'd like to see these functions posted to the forum for others to find. I need the following API calls, ideally using xmlapi.php.inc syntax...

    - Create subdomain
    - Delete subdomain
    - Create mysql db
    - Delete mysql db
    - Add user to db
    - Park domains
    - Unpark domains

    Thanks for the help.

    Chuck
     
  6. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Parking a domain is just the following API1 function:

    HTML:
    <cpanel Park="park(domain)">
    This means:

    API Version: 1
    Module: Park
    Function: park
    Argument: domain

    Unparking a domain is just the following API1 function:

    HTML:
    <cpanel Park="unpark(domain)">
    For everything else you mentioned, you can refer to:

    http://forums.cpanel.net/f42/function-create-ftp-account-email-mysql-database-112153.html
     
  7. cachilupi

    cachilupi Member

    Joined:
    Jul 24, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    Very strange, it appears that I'm doing everything correctly (famous last words), but I only get a "no valid command given" error.

    Here's the full debug dump:

    Code:
    
    RAW API1 CALL:
    <cpanelaction><module>Park</module><func>park</func><apiversion>1</apiversion><args>domainhere.com</args></cpanelaction>
    
    
    
    QUERY:
    https://67.227.138.12:2083/xml-api/cpanel?user=altadev&amp;xmlin=%3Ccpanelaction%3E%3Cmodule%3EPark%3C%2Fmodule%3E%3Cfunc%3Epark%3C%2Ffunc%3E%3Capiversion%3E1%3C%2Fapiversion%3E%3Cargs%3Ealtastreetyeeha.com%3C%2Fargs%3E%3C%2Fcpanelaction%3E
    
    RAW XML:
    
    <?xml version="1.0" ?>
    <cpanelresult><apiversion>1</apiversion><type>text</type><data><result>0</result><reason>No Valid Command Given.</reason></data></cpanelresult>
    
    
    object(SimpleXMLElement)#7 (3) {
      ["apiversion"]=>
      string(1) "1"
      ["type"]=>
      string(4) "text"
      ["data"]=>
      object(SimpleXMLElement)#6 (2) {
        ["result"]=>
        string(1) "0"
        ["reason"]=>
        string(23) "No Valid Command Given."
      }
    }
    SIMPLEXML OBJ:
    
    
    Any thoughts? This is killing me!
     
  8. cachilupi

    cachilupi Member

    Joined:
    Jul 24, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    Other helpful information.

    - cpanel version: 11.24.5-CURRENT
    - cPanel Build: 37629
    - Theme: x3
    - Apache version: 2.0.63
    - PHP version: 5.2.6
    - MySQL version: 5.0.81-community
    - Architecture: x86_64
    - Operating system: Linux
     
  9. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    What happens when you type that URL into your web browser directly (rather than have a script fetch the contents of that page)?
     
  10. cachilupi

    cachilupi Member

    Joined:
    Jul 24, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    Anyone? Could it be a bug with the API? Do I need to talk with my hosting provider about upgrading? Is it just ME!? (I'm not ruling this last one out, it just seems I'm following the API documentation precisely...)

    Thanks,
    Chuck
     
  11. cachilupi

    cachilupi Member

    Joined:
    Jul 24, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    I get the same response...

    Code:
    <cpanelresult>
    <apiversion>1</apiversion>
    <type>text</type>
    <data>
    <result>0</result>
    <reason>No Valid Command Given.</reason>
    </data>
    </cpanelresult>
    
     
  12. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I copied/pasted your command, changed the username to be a user on my test server and things seem to work. However, there may still be a way to determine what is causing this.

    Can you run the following command and send me the output:

    Code:
    tail -n25 /usr/local/cpanel/logs/error_log
    Feel welcome to obfuscate any usernames, IPs and other identifiable information.
     
  13. cachilupi

    cachilupi Member

    Joined:
    Jul 24, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    Here's what tail returns...

    Code:
    2009-07-30 20:04:20 info [cpanel] xml-api/cpanel call failed. Module name is required.
    2009-07-30 20:05:51 info [cpanel] xml-api/cpanel call failed. Module name is required.
    2009-07-30 20:06:35 info [cpanel] xml-api/cpanel call failed. Module name is required.
    
     
  14. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Aha! Make sure you change that &amp; in your URL to an &.
     
  15. cachilupi

    cachilupi Member

    Joined:
    Jul 24, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    Wow, such a small change... but that was it. I had a separate script setting the arg_separator.output to '&amp;' (thanks Drupal!), which was breaking the xmlapi.php.inc script.

    I had to change xmlapi.php.inc on line 65 to the following:
    PHP:
    $args http_build_query($calls,'','&');
    Thanks for your help, guys.
     
  16. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    wow, that does stink. I've updated the distributed version as per that change as I forsee other people hitting that same problem.
     
Loading...

Share This Page