Usage Meter Registration and Usage Report APIs are now part of Cloud Provider APIs on developer.vmware.com

11 min read

We have an important announcement to make – Usage Meter and Usage Report APIs are now part of the Cloud Provider Navigator and can be accessed from the Cloud Provider section on developer.vmware.com. Furthermore, there is a new API for registering Usage Meter with a contract in the VCPP Commerce Portal. Here is how the Usage API page looks like on developer.vmware.com.

In this blog post, we will demonstrate the steps of registering a Usage Meter instance, getting information and downloading usage reports.

Before using the aforementioned APIs, there are a few prerequisites that need to be satisfied.

Prerequisites

  1. A refresh token generated from Cloud Partner Navigator/User Profile/API Tokens. Information can be found here or scroll to the Generating an Access Token section in this blog post.
  2. An access token generated from the Cloud Partner Navigator refresh token. Read here or scroll to the Generating an Access Token section in this blog post.

Note: A generated access token expires after 30 minutes so you need to regenerate it once in a while.

Generating an Access Token for Authentication

To execute the API requests described in this blog post, you will need to generate a refresh token from Cloud Partner Navigator (CPN) and then execute a POST request to the Cloud Services Portal gateway to get the access token with which you will authenticate with the CPN service – Usage Insight.

The Usage Insight service is the service which will register your Usage Meter with a contract in the Commerce Portal and generate reports for a Usage Meter instance.

Now let’s see how to generate an access token:

  1. Log in to Cloud Partner Navigator.
  2. Switch to the organization for which you wish to register a Usage Meter or download usage reports.
  3. Under your username, click My Account.
  4. Click on the API Tokens tab.
  5. In the API Tokens page, click GENERATE TOKEN.
  6. Copy the token and click Continue.

Note: Save your refresh token somewhere as you will need it repeatedly to generate an access token for your usage API calls.

  1. In your API client, make the following POST Request to the Cloud Partner Navigator Service Gateway to generate an access token.

This access token you will use to authenticate with Usage Insight when sending the request for registering your Usage Meter with a contract in the Commerce Portal.

See the sample request and response:

Sample cURL Code:

Note: Replace the refresh token with your own generated from the CPN API Token page.

  1. Copy the access token from the response. Use it when executing the API requests described in this blog post.

Checking if a Usage Meter instance is registered

Before registering a Usage Meter, check if it has already been registered with Usage Insight.

Here is how to do it:

  1. Execute the following GET registration request:

  • Use the UUID of your Usage Meter.
  • Use the generated access token to authenticate to the service.
  1. If your registration is successful, you will get the following response: Status 200 OK, also a contract number, and a site name. See the screenshot below:

Sample cURL Code

Note: Replace the Usage Meter UUID with your own. You can find it in your Usage Meter web application, under the About tab. Use the access token you generated for the authorization.

Registering a Usage Meter in the Commerce Portal

To register your Usage Meter with a contract in the Commerce Portal using the new REST API, you will need to authenticate with the Usage Insight service to which to send the registration request.

Here are the exact steps:

  1. Send POST request to the Usage Insight service, which will handle the registration of the Usage Meter instance with a contract in the Commerce Portal.

  1. In the body of the request, you must specify the following:

  1. For the authorization with the Usage Insight service, use the generated access token.
  1. Execute the request. If the Usage Meter registration is successful, then you will get code 202. See an example below:

If this Usage Meter has already been registered, you will get code 201.

  1. Go to the VMware Commerce portal to verify if Usage Meter is registered with the specified contract and org site.

Sample cURL code

Note: Use your Usage Meter details an provide the access token you generated from the CPN refresh token.

Getting Information on All Usage Reports

Usage report API is now dully documented and is ready to be implemented in your organization. Here are the API requests that you can use to automate your usage report generation:

  • Get information on all usage reports for a specific month and year for an organization
  • Download a specific usage report by specifying its reference number retrieved from the get information on all usage reports API request
  • Finally, get information on all reports associated by a usage meter UUID

Get Information on All Usage Reports for a Month

To get information on all usage reports of all Usage Meters in your CPN organization for a particular month and year, do the following:

  1. Execute GET https://ums.vmware.com/usage/api/v1/reports/2023/1 request to the Usage Insight service endpoint.
  2. Provide the month and year for which you wish to get all usage reports for all your registered Usage Meters.
  3. Authenticate to Usage Insight with the generated access token.
  4. If your request is successful, you will get Status 200 OK and a list of all usage reports associated with Usage Meter UUID. Here is an example of the response.

Sample cURL code

Note: Specify a month and a year for which to get information on all usage reports of a CPN organization.

Download a Specific Usage Report

To download a specific Usage Meter report, you need to provide in the parameters of your API request the reference number of that report. To find it, you need first to trigger GET information on all usage reports request. See the Getting Information on All Usage Reports for a Month section.

Here is how to download a specific Usage Meter report:

1. Make a GET request to https://ums.vmware.com/usage/api/v1/reports and specify the following:

  • In the parameters of the request enter the reference number of the report. This value you must retrieve from the request explained in the Get Information on All Reports for a Month section.
  • In the header of the request, you must specify the Accept parameter to be the content type of the report (again get this information from the get information on all usage reports API request)
  • Authenticate to the Usage Insight service by using the generated access code.
  1. The response will be Status 200 OK if the request is successful, and you also get the text of the zipped report. In this example, the response is not decoded as Postman does node decode the content of zipped files.
  1. Save the response.  In Postman, the way to do it is to click Save Response. This way you will download the referenced report.

Sample cURL code

Note: Use the reference number of the report you wish to download the your generated access token.

Get Information on all Reports of a Usage Meter Instance

To get information on all usage reports of a specific Usage Meters, do the following:

  1. Execute a GET request to the Usage Insight service, specifying the month and year for which you wish to get information and the uuid of the usage meter with which the reports are associated.
  1. Provide the generated access token with which to authenticate with the Usage Insight service.
  1. You will get the following response: Status 200 OK and the details of all reports related to this Usage Meter and their reference numbers.

Note: Use the reference number of the reports you wish to download with the GET / https://ums.vmware.com/usage/api/v1/reports API request.

Here is an example of the request and its response.

Sample cURL Code

Note: Specify a month and a year for which to get information on all usage reports associated with the uuid of your usage meter. Replace the Usage Meter UUID in this example with your own.

Conclusion

In a conclusion, you can use those APIs as part of your Usage Meter reporting automation.  Now with the registration of the Usage Meter instance you can fully automate the installation and configuration of your Usage Meter instances.

We will keep enhancing and expanding our Usage Meter-related APIs and want to hear from you about what other APIs we can develop to improve your reporting experience.

The rest of the Usage Meter API requests can be found here. Cloud Partner Navigator and Commerce Portal APIs can be found here and here.

For more questions or queries, leave a comment below or send us an email to [email protected]. There is a Slack channel available to cloud providers where you can also ask your questions.

Source link

You May Also Like

More From Author