I am trying to get the cost of a resource , app service in Azure for a period of time . I use the following
az consumption usage list --query "[?contains(properties.instanceName, '<my resourrce name>')].properties.usageAmount" --output table
But it does not return anything . Gives error
ERROR: (400) Subscription scope usage is not supported for current api version. Please use api version after 2019-10-01
1
ERROR: (400) Subscription scope usage is not supported for current Api version. Please use Api version after 2019-10-01:
The above error says that the Api version you are using is an older version and you need to use a latest Api version which is 2023-11-01
as given in the MSDoc.
And also az consumption usage
command is under preview and development. So as an alternative workaround, use az rest method
to invoke the cost management details and retrieve it as shown below.
az rest --method get --url "https://management.azure.com/subscriptions/$subid/providers/Microsoft.Consumption/usageDetails?api-version=2023-11-01" --query "value[?contains(properties.instanceName, 'apsbjah')].properties.usageAmount" --output table
You can also use a rest API
to get all the usage details of the Azure management group with the URL:
https://management.azure.com/<Resource ID>/providers/Microsoft.CostManagement/query?api-version=2023-11-01
3