andylee

Registered
Aug 15, 2011
3
0
51
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
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
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
 

sirdopes

Well-Known Member
PartnerNOC
Sep 25, 2007
141
0
66
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.
 

andylee

Registered
Aug 15, 2011
3
0
51
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' ]
);
 

gatorheel

Registered
Oct 14, 2011
4
0
51
cPanel Access Level
Website Owner
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.
It's either a bug in the module or in the documentation. The latter states in cpanel_api1_request():

$format - The format for the xml-api to respond in. The valid values here are “xmlâ€, “json†or “ref†(perl hash reference). This will default to returning a perl hash reference when the value is undef.
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