How to Count Operations Across All APIs in Azure API Management Using Policies?

David Michailis 25 Reputation points
2025-01-07T14:49:19.7566667+00:00

Hi,

I need to create an Azure API Management (APIM) policy that returns the count of operations across all APIs. I already have a policy that gives me the names of all APIs and another that returns the operation count for a specific API. However, I’m struggling to combine both of these into a single policy.

For example, in my APIM, I have 3 APIs, each with a different number of operations. I want to iterate through all the APIs, fetch the number of operations for each, and then sum them all together.

Here’s an example:

  • Api 1: 10 Operations
  • Api 2: 32 Operations
  • Api 3: 3 Operations

The expected return value should look like this:

{ "count": 45 }

My approach is to first retrieve all APIs and then iterate through the list of APIs. Based on each API name, I want to call a second REST endpoint to fetch the count of operations for that API. Unfortunately, I can’t seem to iterate over the APIs using a foreach loop in an APIM policy, and I’m unsure how to implement this within the policy itself.

Is it possible to achieve this only using an Azure Policy, or should I consider a different approach? I’ve already implemented this process successfully in an Azure Function, but my manager insists on keeping everything internal within APIM without adding a new endpoint.

Thanks in advance for any help or suggestions! Best regards.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,338 questions
0 comments No comments
{count} votes

Accepted answer
  1. Khadeer Ali 4,315 Reputation points Microsoft External Staff
    2025-01-07T17:21:57.81+00:00

    @David Michailis ,Welcome to Microsoft Q&A Platform!

    Thanks for reaching out your query on fetching the list of Operations across all API's

    You are correct in your approach using an Azure Function, as it is better suited for this task. Azure Functions can handle complex logic like iterating through APIs, aggregating operation counts, and returning a consolidated result. They are scalable, reusable, and provide better debugging and logging capabilities compared to APIM policies. Additionally, Azure Functions avoid the limitations of APIM, such as rate limits, processing time constraints, and performance bottlenecks for heavy computation.

    APIM is not a feasible solution for this requirement because it is designed for lightweight request transformations and routing rather than complex processing. It lacks the ability to perform iterations or aggregation logic efficiently and may encounter timeouts or performance issues when handling multiple external API calls. This makes Azure Functions the ideal choice for your use case. Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.