Skip to main content
cPanel Technical Support has been heavily impacted by hurricane Beryl and our ability to respond to tickets has been hindered as a result. We appreciate your understanding and patience as we address these delays.

Loop through all accounts and run api calls?



  • KostonConsulting
    What are you using to connect to cPanel if you're not using the cPanel XML API PHP class? Where is the $cpanel->api2() function defined? In the cPanel XML API PHP class, you call API2 like so and can set the user: api2_query($user, $module, $function, $args = array())
    The only way I'm aware of not using auth credentials as root is to load up Cpanel::XML in Perl like so: #!/usr/bin/perl BEGIN{ unshift(@INC,'/usr/local/cpanel'); } use Cpanel::XML (); use Data::Dumper (); use XML::Simple (); my $args = { 'cpanel_xmlapi_module' => 'Email', 'cpanel_xmlapi_func' => 'listdomainforwards', 'cpanel_xmlapi_apiversion' => '2', 'cpanel_xmlapi_user' => $user }; my $xml = Cpanel::XML::cpanel_exec_fast( $args ); my $xmlRef = XML::Simple::XMLin($xml); print Data::Dumper::Dumper($xmlRef);
    You can 'ls /var/cpanel/users' to get a list of all the cPanel users.
  • MACscr
    I am actually using the LiveAPI [url=]LiveAPI — PHP. My perl skills are pretty much nil, so I am using php or bash for simple stuff.
  • KostonConsulting
    LiveAPI can only run within the cPanel web server (cpsrvd). You can't run it from the command line as root as the permissions to access the cPanel account are built into cPanel's web server (running on ports 2083 and 2087). If you are running something from the command line, you are no longer in cPanel so you'll need to connect to cPanel via API which means using the XMLAPI to connect.

Please sign in to leave a comment.