azurerestpostman

Azure usageDetails REST API - Cannot filter on tags


I am using PostMan to make a GET callout to Azure's REST API. According to their API Docs on usageDetail, you can use the $filter query parameter to filter on tags like this: tags eq 'Project ID:PR-008016'. I triple checked that the tags exist in Azure and they are correct, but when I use that in the $filter param, I get a 200 response but it returns an empty values array.

For context, this $filter parameter will return data and filter correctly:

$filter=properties/usageStart eq '2020-07-22' and properties/usageEnd eq '2020-08-01'

But when I add the tags filter, it returns the blank values array:

$filter=properties/usageStart eq '2020-07-22' and properties/usageEnd eq '2020-08-01' and tags eq 'Project ID:PR-008016'

Does anyone know if the syntax is incorrect? Or if there is possibly a bug with the Azure REST Api? (this comment suggest there may be a product bug)

Full Endpoint:

https://management.azure.com/subscriptions/{{subscriptionId}}/providers/Microsoft.Consumption/usageDetails?api-version=2019-10-01&$filter=properties/usageStart eq '2020-07-22' and properties/usageEnd eq '2020-08-01' and tags eq 'Project ID:PR-008016'


Solution

  • As you have pointed that, the support for tags is not retroactive and will only apply to usage reported after the tag was applied to the resource. Tag based filtering and aggregation is supported by the $filter and $apply parameters respectively.

    For more details, you could refer to this article.