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:
- Call the Cost Consumption API to get usageDetails
- 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[]'
- Call the Cost Management API to get the cost data
# 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