Tech

Extracting per-organization billing information in CSV format from OnApp

Zack Grindall

Zack Grindall
Cloud Architect

One of the big considerations for service providers adopting a new cloud platform, is how that platform integrates with their existing Business and Operational Support Systems, especially in terms of billing.

This is especially important for Telcos and MSPs with traditional billing systems focused on CDR/EDRs (Call and Event Data Records) rather than the many different kinds of cloud billing enterprise customers actually want and expect to use.

OnApp provides fine grained control of cloud resource access and pricing through our Buckets system – you can read more about that in Jim’s oddly named Buckets blog post. 

Following on from that post, I wanted to explain how to extract billing data on a per-user basis in CSV format from OnApp. This is really handy for integrating OnApp with those external billing and accounting systems.

To do this, we will be using the following API endpoint:

https://yourcloudurl/users/1/monthly_bills

As you can see, this endpoint won’t give us the desired result right now, as it fetches the monthly bill for just that user, so we’ll need to loop through all the users to extract the monthly bills on a per-user basis. The endpoint we need for this is:

https://yourcloudurl/users

 

Here is the code you’ll need:

 

There are a few things you’ll need to edit before running this script:

// Change these details      

$host = "https://demo.onapp.com/".$uri.".json";

$username = "admin";

$password = "changeme";

 

Please change these details to match your OnApp deployment.

 

// Set the month you want to gather monthly bills for

$month = 2;

 

This should be the month in numerical format, without affixing any zeros to the start. For example, for January, just enter 1.

 

You should save this file as monthly_billing.php or use another suitable name. Once downloaded you can simply run this file from the command line (php monthly_bills.php) if you have php-cli installed, or by running it in a web browser if you have php and a web server installed.

Please keep in mind that this code might need optimizing a bit, depending on the number of users you have, and is only intended as an example to get you started.

As always, reach out if you have any questions!