How to make Subscription Id filter work for Azure APIM Report listbyapi

suvra jyoti 151 Reputation points
2021-05-19T15:06:08.687+00:00

Hi All,

I am trying to use the below Azure APIM Rest API.

https://learn.microsoft.com/en-us/rest/api/apimanagement/2019-12-01/reports/listbyapi#reportrecordcontract.

In this i am trying to filter by subscription id (product subscriptions).

I am specifying the request in below format.

https://test-apim.management.azure-api.net/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-test-apim-eus/providers/Microsoft.ApiManagement/service/test-apim/reports/byApi?$filter=subscriptionId%20eq%20'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-test-apim-eus/providers/Microsoft.ApiManagement/service/test-apim/subscriptions/xxxxxxxxxxxxxxxxxxxx'&api-version=2019-12-01

I end up getting BadRequest.

There is no example of using any other filters other than timestamp that is provided, nor am i getting much help on google.

Moreover for the $filter does not specify anything particularly for this API.

Any help/suggestion on this is much appreciated, i need use the same with purpose of billing for apis.

97876-image.png

Thanks

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

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,016 Reputation points
    2021-05-20T05:55:29.523+00:00

    @suvra jyoti As per your request URL https://test-apim.management.azure-api.net/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-test-apim-eus/providers/Microsoft.ApiManagement/service/test-apim/reports/byApi?$filter=**subscriptionId**%20eq%20'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-test-apim-eus/providers/Microsoft.ApiManagement/service/test-apim/subscriptions/xxxxxxxxxxxxxxxxxxxx'&api-version=2019-12-01

    You are trying to filter it based on subscriptionID which is not possible. You can only filter on the set of data that is collected i.e. response from the API.
    I don't see any response filed with the subscriptionID. To know what filters are supported you can try using them in the filter and the API will return you the result as 400 along with an error message if the filter is not supported on that field.

    --------------------------------

    Updated:

    @suvra jyoti My bad. Yes, ResportRecordContract has the property subscriptionId which can be used in the filter condition. The test that I have performed at my end doesn't have this field in my response as well the sample response which there in the document makes me believe with my observation previously.

    If you want to use the filter along with Order by clause you can define the query parameter $orderby with the value of any column as per ResportRecordContract

    Example:
    https://management.azure.com/subscriptions/{subscription ID}/resourceGroups/{Resourcegroupname}/providers/Microsoft.ApiManagement/service/{APIMInstance}/reports/byApi?%24filter=timestamp%20ge%20datetime%272021-05-19T00%3A00%3A00%27%20and%20timestamp%20le%20datetime%272021-05-21T00%3A00%3A00%27&api-version=2019-12-01&%24orderby=name%20desc

    reports/byApi?$filter=timestamp ge datetime'2021-05-19T00:00:00' and timestamp le datetime'2021-05-21T00:00:00' and subscriptionId eq 'c0ba7e7b33044ed09fd11b6a23b233dc'&api-version=2019-12-01"&$orderby=name desc

    As 'orderby' field supports the OData order by query option you can also refer to this document.