Azure APIM - GET total call count for subscription

wallism

Wallism

Posted on September 21, 2023

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").

💖 💪 🙅 🚩
wallism
Wallism

Posted on September 21, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024

Modern C++ for LeetCode 🧑‍💻🚀
leetcode Modern C++ for LeetCode 🧑‍💻🚀

November 29, 2024