none
How to best show a user how many API calls they have made/report RRS feed

  • Question

  • So now my customer wants to see a report on how many API calls they have made.

    It's not in the portal, so I suppose the only way to do it is to make a custom program that will read their login and then use the Management API? Or maybe I can just use the management API for 1 specific user?

    Seems like I have to make a custom application for them. 

    I've already made a new application so I don't have to use API management anymore because they don't have monitization on it. I suppose I'll do something to connect to it.

    Wednesday, November 20, 2019 3:40 AM

Answers

  • API Management has 2 portals and 2 types of users. The Azure Portal is used for API Managers (think users who publish APIs, operations, manage policy, etc.). The Developer Portal is used by developers who are using (think customers) of your API.

    Users are either register themselves through Developer portal. Or you as owner of APIM service can invite/register users from Azure Portal. 

    In order to use an API, the user/customer has to register with the Developer Portal and get a Subscription to a given API and the associated key. So, you have to authenticate them.

    For Metric wise: Once a developer is registered you will be able to report on their activity through API Management. Look for Users item in left side menu of APIM service.

    Or

    The API to get request level analytics is Lists report records by Request.

    GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/byRequest?$filter={$filter}&api-version=2019-01-01

    The response includes the apiId, operationId, userId, subscriptionId to the Product etc, which is beneficial to you for tracking.

    Sample Response :

    {
      "value": [
        {
          "apiId": "/apis/5931a75ae4bbd512a88c680b",
          "operationId": "/apis/5931a75ae4bbd512a88c680b/operations/-",
          "productId": "/products/-",
          "userId": "/users/1",
          "method": "GET",
          "url": "https://apimService1.azure-api.net/echo/resource?param1=sample",
          "ipAddress": "207.xx.155.xx",
          "responseCode": 404,
          "responseSize": 405,
          "timestamp": "2017-06-03T00:17:00.1649134Z",
          "cache": "none",
          "apiTime": 221.1544,
          "serviceTime": 0,
          "apiRegion": "East Asia",
          "subscriptionId": "/subscriptions/5600b59475ff190048070002",
          "requestId": "63e7119c-26aa-433c-96d7-f6f3267ff52f",
          "requestSize": 0
        },
        {
          "apiId": "/apis/5931a75ae4bbd512a88c680b",
          "operationId": "/apis/5931a75ae4bbd512a88c680b/operations/-",
          "productId": "/products/-",
          "userId": "/users/1",
          "method": "POST",
          "url": "https://apimService1.azure-api.net/echo/resource",
          "ipAddress": "207.xx.155.xx",
          "responseCode": 404,
          "responseSize": 403,
          "timestamp": "2017-06-03T00:17:20.5255131Z",
          "cache": "none",
          "apiTime": 6.6754000000000007,
          "serviceTime": 0,
          "apiRegion": "East Asia",
          "subscriptionId": "/subscriptions/5600b59475ff190048070002",
          "requestId": "e581b7f7-c9ec-4fc6-8ab9-3855d9b00b04",
          "requestSize": 0
        }
      ],
      "count": 2
    }

    or

    The API to Lists report records by User

    • Marked as answer by dan276 Wednesday, November 20, 2019 3:17 PM
    Wednesday, November 20, 2019 5:01 AM
    Moderator

All replies

  • API Management has 2 portals and 2 types of users. The Azure Portal is used for API Managers (think users who publish APIs, operations, manage policy, etc.). The Developer Portal is used by developers who are using (think customers) of your API.

    Users are either register themselves through Developer portal. Or you as owner of APIM service can invite/register users from Azure Portal. 

    In order to use an API, the user/customer has to register with the Developer Portal and get a Subscription to a given API and the associated key. So, you have to authenticate them.

    For Metric wise: Once a developer is registered you will be able to report on their activity through API Management. Look for Users item in left side menu of APIM service.

    Or

    The API to get request level analytics is Lists report records by Request.

    GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/byRequest?$filter={$filter}&api-version=2019-01-01

    The response includes the apiId, operationId, userId, subscriptionId to the Product etc, which is beneficial to you for tracking.

    Sample Response :

    {
      "value": [
        {
          "apiId": "/apis/5931a75ae4bbd512a88c680b",
          "operationId": "/apis/5931a75ae4bbd512a88c680b/operations/-",
          "productId": "/products/-",
          "userId": "/users/1",
          "method": "GET",
          "url": "https://apimService1.azure-api.net/echo/resource?param1=sample",
          "ipAddress": "207.xx.155.xx",
          "responseCode": 404,
          "responseSize": 405,
          "timestamp": "2017-06-03T00:17:00.1649134Z",
          "cache": "none",
          "apiTime": 221.1544,
          "serviceTime": 0,
          "apiRegion": "East Asia",
          "subscriptionId": "/subscriptions/5600b59475ff190048070002",
          "requestId": "63e7119c-26aa-433c-96d7-f6f3267ff52f",
          "requestSize": 0
        },
        {
          "apiId": "/apis/5931a75ae4bbd512a88c680b",
          "operationId": "/apis/5931a75ae4bbd512a88c680b/operations/-",
          "productId": "/products/-",
          "userId": "/users/1",
          "method": "POST",
          "url": "https://apimService1.azure-api.net/echo/resource",
          "ipAddress": "207.xx.155.xx",
          "responseCode": 404,
          "responseSize": 403,
          "timestamp": "2017-06-03T00:17:20.5255131Z",
          "cache": "none",
          "apiTime": 6.6754000000000007,
          "serviceTime": 0,
          "apiRegion": "East Asia",
          "subscriptionId": "/subscriptions/5600b59475ff190048070002",
          "requestId": "e581b7f7-c9ec-4fc6-8ab9-3855d9b00b04",
          "requestSize": 0
        }
      ],
      "count": 2
    }

    or

    The API to Lists report records by User

    • Marked as answer by dan276 Wednesday, November 20, 2019 3:17 PM
    Wednesday, November 20, 2019 5:01 AM
    Moderator
  • Yes, it's too bad the API management doesn't let the end user do this without us having to write custom code. That's the whole point using API management. All this custom code I'm having to write, it's easier to just make my own API. I'll have to use the API as you mentioned
    Wednesday, November 20, 2019 3:17 PM