I am trying to use the Azure Management API to determine an Azure Subscription daily costs. The documentation of the query I am running is here: https://learn.microsoft.com/en-us/rest/api/cost-management/query/usage?tabs=HTTP .
I would like to retrieve the daily costs, unfortunately the results I get are grouped "daily" by an unknown Time Zone, which makes the query not easy to interpreter.
The query I run is the following:
- scope: subscriptions/xxxxx-xxxxx-xxxxx
- api-version: 2022-10-01
- body:
{
"type": "ActualCost",
"timeframe": "Custom",
"timePeriod": {
"from": "2023-03-16T00:00:00+00:00",
"to": "2023-03-17T00:00:00+00:00"
},
"dataset": {
"granularity": "Daily",
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "SubscriptionId"
}
]
}
}
and the answer I receive is:
{
"id": "subscriptions/xxxxxxx/providers/Microsoft.CostManagement/query/zzzzzzzzzz",
"name": "ttttttttttttt",
"type": "Microsoft.CostManagement/query",
"location": null,
"sku": null,
"eTag": null,
"properties": {
"nextLink": null,
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "SubscriptionId",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"rows": [
[
8.603384519054256,
20230316,
"yyyyyyyyyyyyyyyyyyyy",
"EUR"
]
]
}
}
So I receive as last day yesterday's data, no data for today. If I run the same query at 6PM I receive also today's costs, considering them starting from lower values, like "midnight just passed". Please note that when I specify a time interval, I set the dates to UTC-0 in my query (I also tried the Z format with the same result).
Anyone knows how to change the timezone that the Azure Management API use when grouping for Date?
Thanks, Michele
By default Azure Management API uses UTC time zone but you can change the time zone in two ways,
I have taken references from the MS doc
API