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.

cpanel api error please help

Discussion in 'cPanel Developers' started by andylee, Aug 15, 2011.

  1. andylee

    andylee Registered

    Joined:
    Aug 15, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    I am use perl Cpanel::PublicAPI and get the following error message

    The server was not able to find the document (./-api/cpanel) you requested.
    Please check the url and try again. You might also want to report this
    error to your web hosting provider.

    may I ask what is actually wrong with this

    Great Thanks
     
  2. 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 Andy,

    Since all remote API calls to cPanel start either as json-api/cpanel or xml-api/cpanel, I assume is misconfigured in your code. Or it's possible that you've found a bug in Cpanel::PublicAPI. Please provide an example so we can pinpoint the problem.

    Best Regards,
    -DavidN
     
  3. sirdopes

    sirdopes Well-Known Member
    PartnerNOC

    Joined:
    Sep 25, 2007
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    16
    Basically, u just need to set the output to xml, like the following:

    my $xml_add_database = $cp->cpanel_api1_request('cpanel', { 'module' => 'Mysql', 'func' => 'adddb' }, [ "$db_name" ], 'xml');



    It doesn't have a return type set by default so it is not using xml-api as part of the url and just trying to use -api.
     
  4. andylee

    andylee Registered

    Joined:
    Aug 15, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    here is my code :
    just copy from the instruction
    =====================================

    #!/usr/bin/perl -w
    use lib ("test");
    use cPanel::PublicAPI;
    my $cp = cPanel::PublicAPI->new('user' => 'waylinks', 'pass' => 'np55cg55');
    $cp->cpanel_api1_request('cpanel',
    {
    'module' => 'Mysql',
    'func' => 'adduserdb',
    },
    [ 'waylinks_db', 'waylinks_ttttt', 'ALL' ]
    );
     
  5. andylee

    andylee Registered

    Joined:
    Aug 15, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    I found the error there should be a 'xml' follow the parameters

    Great tks
     
  6. gatorheel

    gatorheel Registered

    Joined:
    Oct 14, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    It's either a bug in the module or in the documentation. The latter states in cpanel_api1_request():

    If no $format is specified, it appears the mod should default to JSON (by looking at sub _init_serializer) and hashes. But, in PublicAPI.pm, line 437, $CFG{'serializer'} is used before it's initialized (in line 440), so instead of being defaulted it's left blank. Looks like someone didn't check their code with warnings enabled. :)

    So, either swap the order (preferred) or change the docs to make $format required.

    Matt
     
Loading...

Share This Page