Example: Reports REST API

This example shows how to use the cloud operations Reports REST API for generating usage reports for a cloud subscription.

The example takes you through retrieving a list of metrics that are available for the cloud subscription and then generating a report for a specific metric and time period.
Before you begin
All API calls require a valid cross site forgery request (CSRF) token in the IBM-CSRF-TOKEN header of the call. Obtain a CSRF token by using POST /instance/services/csrf_token. For more information, see Preventing cross site request forgery.
Retrieve metrics
Use the following call to display a list of metrics that are available for the cloud subscription:
GET /instance/services/metrics
A list of metrics is returned. The list includes the metric name and the scope of the metric. The scope indicates whether the metric is available for all environments or only specific ones.
Generate a report
You can then choose the metric you are interested in, for example, the maximum number of concurrent users for a specific day:
GET /instance/services/reports?start_day=2019_01_01&metric=maximum_concurrent_users
You must always include a start day in the call. If you don't include an environment, the call returns usage data for all environments. If you want to filter the report to show the usage data for a specific environment, such as the development environment, add the environment parameter to the call:
GET /instance/services/reports?start_day=2019_01_01&metric=maximum_concurrent_users&environment=dev
If you want to see usage data, for example, for 30 days from the start date, modify the call as follows:
GET /instance/services/reports?start_day=2019_01_01&days=30&metric=maximum_concurrent_users&environment=dev
If you're interested in the 30-day period prior to the start date, use a negative value for the days parameter:
GET /instance/services/reports?start_day=2019_01_01&days=-30&metric=maximum_concurrent_users&environment=dev