DEV Community

Wallism
Wallism

Posted on

Azure APIM - GET total call count for subscription

How do you get the total call count for a given subscriptionId from Azure APIM?
The easy but not overly useful way is in the Azure Portal, go to your APIM, then select the Analytics blade (under Monitoring), select the Subscriptions tab, pick your time range and there they are.

Programatically

How to get this data programatically is far more useful and is also relatively easy, the only tricky part is getting the token.
First, check out the docs.

Your call will look like this:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/bySubscription?$filter={$filter}&api-version=2023-03-01-preview

You can run that in Postman or similar tool (e.g. open source Hoppscotch), however you will need an access token.

How to get an access token

The easiest way is, hit that "Try It" button on the docs page, after you are logged in, you should see a Bearer token in the Request Preview section. You can use that. I dropped mine into jwt debugger to check the expiry, it lasts one hour.

OR - generate your own...

I followed these instructions :)

Essentially (super brief summary), call this POST https://login.microsoftonline.com/{{AAD_name}}/oauth2/token with client_id and client_secret specified in the body (can't recall why but in my Postman my body is "x-www-form-encoded").

Top comments (0)