Hello World, using API from the bash shell prompt

kitchin

Member
Sep 18, 2011
24
0
51
cPanel Access Level
Root Administrator
The API example for listaccts is
Code:
https://example.com:2087/xml-api/listaccts?searchtype=user&search=luv
As a Hello World program, I would like to do the same thing from the bash shell prompt. Say, using a perl script:

$ perl hello.pl
Code:
#!/usr/bin/perl
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use Whostmgr::Accounts;
use Data::Dumper;

$x= Whostmgr::Accounts::_listaccts();
$_= Dumper($x);
print; # empty since:

$ENV{'REMOTE_USER'}= 'root';
$hasroot = Whostmgr::ACLS::hasroot();
print "hasroot=[$hasroot]\n"; # false
Is there wrapping code to get the API to accept the perl/shell script as root? I am logged in as root, after all.

The shell scripts in /scripts do not have the functions I want, such as cPAddons stuff. So I am trying to use the web API. Really I just want to install Wordpress as a cPAddon without having to use the WHM web interface.

Alternatively, what is the easiest way to get a script like this into the WHM web interface? None of the API examples start that far back at the beginning: where do you put the file and how do you call it.
 

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
Houston, TX
cPanel Access Level
Root Administrator
if /root/.accesshash exists you can use that for authentication. I use the following curl statement to make API queries from the shell:

curl -k -H "Authorization: WHM root:`cat ~/.accesshash | tr -d "\n"`" 'https://localhost:2087//xml-api/listaccts'

as far as reasonable parsing of that return in bash.. have fun.

The cPanel::PublicAPI (see CPAN) perl module will auto detect this as well.