Retrieve cPanel Account Statistics Using UAPI

  WHM

Introduction

This document explains how to retrieve cPanel account statistics using the UAPI command-line interface. The StatsBar::get_stats API allows administrators to obtain usage information such as:

In this example, we retrieve only the bandwidth usage and disk space usage for a cPanel account.


Prerequisites

Before running the command, ensure the following requirements are met:

Verify the UAPI command:

$ which uapi

Example output:

$ /usr/bin/uapi

Reference Links:

How to check cPanel User Resource Usage using UAPI


Command Syntax

$ uapi --output=jsonpretty --user=<cpanel user name > StatsBar get_stats display='bandwidthusage|diskusage'

Example

Suppose the cPanel account username is example.

Run:

$ uapi --output=jsonpretty --user=example StatsBar get_stats display='bandwidthusage|diskusage'

Example Output

{
  "apiversion": 3,
  "func": "get_stats",
  "module": "StatsBar",
  "result": {
    "data": [
      {
        "item": "Monthly Bandwidth Transfer",
        "id": "bandwidthusage",
        "count": "6.73 GB",
        "max": "unlimited",
        "percent": 0
      },
      {
        "item": "Disk Space Usage",
        "id": "diskusage",
        "count": "78.71 GB",
        "max": "unlimited",
        "percent": 0
      }
    ],
    "status": 1
  }
}

Expected Result

A successful execution returns:


Common Use Cases


Conclusion

The StatsBar::get_stats UAPI function provides a simple and efficient way to retrieve cPanel account resource statistics from the command line. By specifying the desired statistics using the display parameter, administrators can obtain structured JSON output that is easy to read, automate, and integrate into monitoring or reporting workflows. This method is particularly useful for auditing account usage, tracking resource consumption, and supporting operational tasks such as capacity planning and migrations.

Related Articles:

How to create a database user in cpanel via cli using the uapi tool

How to create db user and password and give privileges in cpanel using uapi in terminal

LEAVE A COMMENT