How to get Disk Space Usage and Monthly Bandwidth Transfer from cPanel to my website in PHP

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My quesiton was:

I’m wondering how can I show (get) disk space usage and monthly bandwidth transfer on my website in the same way as it’s shown when I login to my cPanel account. Is there an api from cPanel for this or is this a general method to do so? I’m using PHP.

This answer, by user richsage, was:

cPanel/WHM has an API which offers access to both the elements you’re looking for. See the API docsfor more details. The bandwidth and disk usage modules in API 1 output HTML, however API 2 has anaccount summary method which will return the diskused parameter in the appropriate format (XML/JSON as requested).

Written by Nikola Brežnjak