question

suvrajyoti-2505 avatar image
0 Votes"
suvrajyoti-2505 asked MayankBargali-MSFT commented

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

Hi All,

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

https://docs.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
image.png (65.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered MayankBargali-MSFT commented

@suvrajyoti-2505 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:

@suvrajyoti-2505 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.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Mayank,

It is possible to filter based on subscription id. I got it to work using the timestamp and the subscription id filter together and giving the subscription id in the below format along with timestamp and that i got to know from the error response..we atleast need to give the ge part in timestamp.

var requestUri = "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";

Thanks

0 Votes 0 ·

Could anybody tell me how to use the Order by filter in the above report by api.?

0 Votes 0 ·

@suvrajyoti-2505 My bad. I have updated the answer due to the comment limit. Please let me know if you need any assistance.

1 Vote 1 ·
Show more comments