Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

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.

Hello World, using API from the bash shell prompt

Discussion in 'cPanel Developers' started by kitchin, Sep 18, 2011.

  1. kitchin

    kitchin Member

    Sep 18, 2011
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator
    The API example for listaccts is
    As a Hello World program, I would like to do the same thing from the bash shell prompt. Say, using a perl script:

    $ 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.
  2. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Apr 29, 2005
    Likes Received:
    Trophy Points:
    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.

Share This Page