0

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

Michele
  • 101
  • 1
  • 6
  • Hi, if I understand well your question, I am running this query from Italy, and the endpoint I am using is https://management.azure.com. – Michele Apr 27 '23 at 14:24

1 Answers1

0

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

POST https://management.azure.com/subscriptions/xxxxxxxxxxxxxxxxx/providers/Microsoft.CostManagement/query?api-version=2022-10-01
  1. By passing timeZoneOffset parameter in the request URL like if you want to group the costs according to the pacific standard time then set -480(minutes)

enter image description here

  1. In the request body UTC(current time: 2023-03-28T08:48:00-08:00), you will get today's cost for pacific standard timezone. I have changed the from and to timeframe. I have got the cost for today as well.

enter image description here

enter image description here

enter image description here

Harshitha
  • 3,784
  • 2
  • 4
  • 9
Ikhtesam Afrin
  • 897
  • 1
  • 1
  • 6
  • Hi @Ikhtesam, thank you for your answer. I had time to check it in deep, and the timezone in the timePeriod object is used as a filter (to show more or less days in the result), not as an aggregation criteria. – Michele May 03 '23 at 14:14