2

I have an issue trying to filter usages for Azure Consumption, as specified in the official documentation, based on:

properties/resourceName eq '{resourceName}

The complete URI is:

$ConsumtionUsagesUri = "https://management.azure.com/subscriptions/$subId/providers/Microsoft.Billing/billingPeriods/$BillingPeriod/providers/Microsoft.Consumption/usageDetails?$expand=meterDetails,additionalProperties&$filter=properties/resourceName eq '{resourceName}'&api-version=2019-10-01"

The query returns all the results regardless of filter. Thanks everyone for your help!

bozx
  • 53
  • 4
  • Correction: I am trying to obtain usage details for only one managed disk by filtering based on `properties/resourceId`, which is an `Id` of that managed disk. – bozx Apr 29 '21 at 18:11
  • Same issue, I tried also using tags as the syntax is simpler, URI-encoding the filter but nothing works (filter is not respected). Did you find a solution? – spygi Aug 27 '21 at 08:49
  • I also cannot get the filter to work, regardless of what I try. One note about your code though: if you are using PowerShell the `$` symbol is special inside of a string with double quotes, so `$filter` would be interpreted as the value of the variable $filter. You probably want to escape the `$` using the back-tick character like this: `$filter – Joe Skeen Nov 16 '22 at 17:35

2 Answers2

0

This may be because your syntax is not correct. If you would like to filter by resource name, you have to follow this syntax. Please note that the case sensitivity may return different result.

properties/instanceName eq '{instanceName}'

For other syntax, please check the Azure Consumption API repo. I believe this will work with Azure Consumption API.

DonDave
  • 63
  • 10
  • I am following this article https://learn.microsoft.com/en-us/rest/api/consumption/usagedetails/list#uri-parameters where it says we can use `properties/resourceId`. My URI looks like this:`"https://management.azure.com/subscriptions/$SubscriptionId/providers/Microsoft.Billing/billingPeriods/$BillingPeriodCurrent/providers/Microsoft.Consumption/usageDetails?$filter=properties/resourceId eq '$ManagedDiskId'&api-version=2019-10-01"`. Am I doing something wrong? – bozx Apr 29 '21 at 18:07
  • Anyone got solution of how to pass filters. Nothing worked for me. `https://management.azure.com/subscriptions//providers/Microsoft.Consumption/usageDetails?$filter=tags eq 'application:app2'&api-version=2021-10-01` – Sourabh Bhutani Nov 22 '21 at 12:23
0

it will be like => ?api-version=2021-10-01&$expand=meterDetails&metric=amortizedcost&$filter=tags/Vendor eq '******'

API documentation is not correct.

Rakesh Prasad
  • 602
  • 1
  • 13
  • 32