az consumption usage list ... ERRORs out with : Please use api version after 2019-10-01

sekhemrekhutawysobekhotep 41 Reputation points
2022-03-31T16:38:38.827+00:00

When I execute

az consumption usage list

from a terminal it errors out with message

Command group 'consumption' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
(400) Subscription scope usage is not supported for current api version. Please use api version after 2019-10-01 (Request ID: 58398c21-5095-4517-952b-8266b612fd3b)

I am on Ubuntu 20.04 linux ... here is how I installed azure cli

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

this gives me version

.....................

az --version

azure-cli 2.34.1

core 2.34.1
telemetry 1.0.6

Dependencies:
msal 1.16.0
azure-mgmt-resource 20.0.0

Python location '/opt/az/bin/python3'
Extensions directory '/home/ave/.azure/cliextensions'

Python (Linux) 3.8.12 (default, Mar 2 2022, 07:26:21)
[GCC 9.3.0]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

........................

So how to I satisfy above error message ? namely How can I execute

az consumption usage list

???

ALSO --- what is proper tag when asking a question on azure cli tool az ?

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,027 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-04-21T16:48:54.8833333+00:00

    The issue is still occurring in the az latest version 2.47.0
    az --version azure-cli 2.47.0 core 2.47.0 telemetry 1.0.8 Dependencies: msal 1.20.0 azure-mgmt-resource 22.0.0 </br>

    Instead of using CLI you can call the APIs in your scripts or via command line:

    1. Call the Cost Consumption API to get usageDetails
    2. Usage Details - List - REST API (Azure Consumption) | Microsoft Learn
    
    # Set your Azure subscription ID
    subscriptionId=$(az account show --query id -o tsv)
    
    # Set your authorization token
    authToken=$(az account get-access-token --resource=https://management.azure.com/ --query accessToken -o tsv)
    
    # Set the start and end dates in YYYY-MM-DD format
    startDate="2023-04-01"
    endDate="2023-04-17"
    
    # Call the Cost Consumption API to get usageDetails
    usage=$(curl -s -X GET -H "Authorization: Bearer $authToken" -H "Content-Type: application/json" "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.Consumption/usageDetails?api-version=2023-03-01&$filter=properties/usageEnd ge '${startDate}' AND properties/usageEnd le '${endDate}'")
    
    echo "${usage}" | jq -r '.value[]'
    
    
    1. Call the Cost Management API to get the cost data
      1. Query - Usage - REST API (Azure Cost Management) | Microsoft Learn
        # Set your authorization token
        authToken=$(az account get-access-token --resource=https://management.azure.com/ --query accessToken -o tsv)
    
        # Set the query to get the cost data
        query='{
            "type": "ActualCost",
            "timeframe": "Custom",
            "timePeriod": {
                "from": "'"$startDate"'",
                "to": "'"$endDate"'"
            },
            "dataset": {
                "granularity": "Monthly",
                "aggregation": {
                    "totalCost": {
                        "name": "Cost",
                        "function": "Sum"
                    }
                },
                "grouping": [
                    {
                        "type": "Dimension",
                        "name": "SubscriptionId"
                    },
                    {
                        "type": "Dimension",
                        "name": "BillingMonth"
                    }
                ]
            }
        }'
    
        # Call the Cost Management API to get the cost data
        response=$(curl -s -X POST -H "Authorization: Bearer $authToken" -H "Content-Type: application/json" -d "$query" "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.CostManagement/query?api-version=2022-10-01")
    
    
        # Parse the response to get the data for each resource
       echo $response | jq -r '.properties.rows[] 
    

    I put my thoughts here, I am open for opinions https://github.com/dummy-andra/CloudEngineerNotes/blob/91fa0f28fd25e959fde5ba63ccd2e5e73862ee6c/0-Cloud/Azure/(400)%20Subscription%20scope%20usage%20is%20not%20supported%20for%20current%20api%20version.%20Please%20use%20api%20version%20after%202019-10-01.md

    1 person found this answer helpful.

  2. Andy Ball 11 Reputation points
    2023-01-20T10:13:16.3133333+00:00

    I'm getting this issue also with latest Powershell as per below, any eta on a fix ? has a bug been filed

    CommandType Name Version Source


    Cmdlet Get-AzConsumptionUsageDetail 2.0.0 Az.Billing

    0 comments No comments

  3. az 0 Reputation points
    2023-04-13T10:12:04.4333333+00:00
    az consumption budget list
    

    Command group 'consumption' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus (422) This operation is not supported in the version specified in the request. Please use version 2018-12-01-preview or later. az --version azure-cli 2.47.0 core 2.47.0 telemetry 1.0.8 Dependencies: msal 1.20.0 azure-mgmt-resource 22.0.0