Issue calling Bandwidth::query UAPI from WHM?

Saeven

Active Member
Jun 23, 2003
26
0
151
Ottawa
cPanel Access Level
Reseller Owner
Twitter
Trying to get a list of domains and their bandwidth usage, seemed like the UAPI's Bandwidth::query method was the best bet.

I am doing this server-to-server, and when I issue the call per the instructions here:
Use WHM API to Call cPanel API and UAPI - Software Development Kit - cPanel Documentation

I get this return for any request:
Code:
{"apiversion":3,"func":"query","result":{"messages":null,"errors":null,"status":1,"metadata":{},"data":{}},"module":"Bandwidth"}
My request parameters are as follows:
Code:
'cpanel_jsonapi_user' => $plan->getUsername(),
'cpanel_jsonapi_apiversion' => 3,
'cpanel_jsonapi_module' => 'Bandwidth',
'cpanel_jsonapi_func' => 'query',
'grouping' => 'domain',
'interval' => 'daily',
'protocols' => 'http',
'timezone' => 'UTC',
'start' => $start,
'end' => $end,
System is running WHM 54.0 (build 28)

Thanks for any insight you can offer! The docs state that the JSON response should return an integer.
 

lhoezee

Member
Dec 22, 2008
9
1
53
Hello,

I just tried this out and it worked for me. I'm using WHM 62 (Build 15).

Make sure $start and $end are in unix timestamp format.

I got it to work with the following:
PHP:
$response = $cpanel->execute_action(3, 'Bandwidth', 'query', $domainModel->getUsername(), [
    'grouping' => 'domain',
    'interval' => 'daily',
    'protocols'   => 'http',
    'timezone'  => 'UTC',
    'start' => strtotime('-10 days'),
    'end'   => time()
]);
Notice I just went back 10 days. If I used time() for both start and end I get no data.

Also, as a side comment / question. As I was reading your question I had the impression you wanted all domains on the server for your report? I wanted to confirm this only shows bandwidth for the domain (and add-on domains) for the provided cPanel username.
 
  • Like
Reactions: cPanelMichael