Use CLI to get billable usage

Hi all

Has anybody managed to put together a CLI script that will query the billing API and - after formatting - return a list of users consuming specific licenses and an overall count? Looking to potentially schedule this to run in a customer's own environment nightly via a batch processor app and based on the result count send them an alert through another means. Starting point is to be able to filter out specific license types, get just the name of the users and an overall count.

Hi Vaun,

You can use the gc license user list -a command and this will return a list of all the users and their corresponding licenses. This does not return user info (e.g. name or email) just the user id and the license they consume. You could probably string together a CLI/JQ command to do this, but since you are trying to map the users to licenses and filter the entire list you might want to consider writing a simple python or node script to do this.

For example, here is a simple python script that dumps out the user and license information in a CSV format. You just need to set up the OAUTH client information as environment variables:

import PureCloudPlatformClientV2
import os

CLIENT_ID = os.environ["GENESYSCLOUD_OAUTHCLIENT_ID"]
CLIENT_SECRET = os.environ["GENESYSCLOUD_OAUTHCLIENT_SECRET"]
CLIENT_API_REGION = os.environ["GENESYSCLOUD_API_REGION"]


PureCloudPlatformClientV2.configuration.host = 	CLIENT_API_REGION
apiClient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(CLIENT_ID, CLIENT_SECRET)
usersApi = PureCloudPlatformClientV2.UsersApi(apiClient)
licenseApi = PureCloudPlatformClientV2.LicenseApi(apiClient)

users = usersApi.get_users()

for user in users.entities:
    userLicenses = licenseApi.get_license_user(user.id)
    
    for license in userLicenses.licenses:
      print("{},{}".format(user.email,license.id))

You could then structure or filter the data any way you want. I hope that helps.

Thanks,
John Carnell
Manager, Developer Engagement

Hi John - thanks for this

Why I"m after this is to be able to get the actual billing usage so that I can schedule this query daily/nightly for my customer. At the moment they have to manually log into the UI to check their concurrent billing usage. So not so much what users have what licenses, but what's actually being consumed - if that makes sense.

That way I can have them sent a notification daily so they'll know whether they've gone over the usage for the month already, or are approaching it etc. There's an idea on the aha site to have something nicer to achieve this but for our concurrent customers there's really nothing to help warn them if they're getting close to going over.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.