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.

Issue calling Bandwidth::query UAPI from WHM?

Discussion in 'cPanel Developers' started by Saeven, Feb 23, 2017.

Tags:
  1. Saeven

    Saeven Active Member

    Joined:
    Jun 23, 2003
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    151
    Location:
    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.
     
  2. lhoezee

    lhoezee Member

    Joined:
    Dec 22, 2008
    Messages:
    9
    Likes Received:
    1
    Trophy Points:
    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.
     
    cPanelMichael likes this.
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,037
    Likes Received:
    1,280
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page