vCenter Chargeback provides a fully featured API that allows to automate many tasks like user and rights management, cost configuration or reporting.
Chargeback API is REST-based, this means that it will receive requests and send responses using HTTP protocol and methods. CBM API implements a set of basic CRUD operations, and each of them maps with an HTTP method as shown in he below table.
API syntax is actually very easy, it is composed of:
- Request method
- Base URL
- API signature
It’s better illustrated with an example:
We can map the above example with the different elements of the API syntax:
POST–This is the request method
https://chargeback.corp.local/vCenter-CB/api– This the base URL
/login– This is the API signature, composed of the path to the API we want to call.
We have also included the API version, I usually includes the version as an URL parameter but as we will see later is not really required. Some of the tasks will need also URL parameters that will be placed after the signature.
If there is need for more complex information either in the request or the response an XML payload have to be sent, just like in many other REST APIs. Even to perform a simple login an XML has to be sent, just like the next example.
For our first ride with CBM API we will use Firefox REST Client add-on, can be found here, this handy add-on provides a visual an easy way to quickly ramp up with any REST API. I personally have used it a lot with Chargeback to try the different API operations during a development project for a customer.
I’m not going to review every possible API, just a few examples to illustrate how it works.
This is the most basic operation of all. In the REST Client paste the XML payload in the Body area, select POST as the method to use and fill the URL field.
Get hierarchy list
Not every task needs an XML payload, in the following example we are going to get a list of the hierarchies using a GET method and with no message body. The URL to make the request would be:
After executing the request we can see in the REST Client the response from Chargeback in XML format.
If we go to Chargeback web UI we’ll see the listed hierarchies.
Get all Pricing Models
Another simple request with no XML payload, with a similar syntax to the previous one:
It will produce however a much more detailed response XML with the details of each of the configured Pricing Models.
Add a new hierarchy
Invoked using a POST method, that corresponds with the CREATE operation from the table at the beginning of the post. The syntax for the request would be:
In this case I’m not going to put the version as a parameter. An XML payload with the details of the new hierarchy is required.
Login to Chargeback web interface to check that the new hierarchy is there.
I hope that now you have at least a general understanding of how Chargeback API works and how easy is to interact with it. In the second post of the series we will review how to automate Chargeback using vCenter Orchestrator.