2

I'm trying to add a query into a Workbook in Azure Monitor that queries for the month-to-date usage costs for my Azure subscription.

When I construct the query and run it, I receive the following error message:

BadRequest: Invalid query definition, Dataset is invalid or not supplied.

However, the documentation for this REST API call specifically indicates that the datasets property of the body is not required.

Docs: https://learn.microsoft.com/en-us/rest/api/cost-management/query/usage

Screenshot of docs:

enter image description here

Here's a screenshot of what my query looks like in the Workbook:

enter image description here

Question: How do I properly construct the body for this request, when the documentation doesn't properly explain it?

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • is it ok f you leave the dataset field out of the request then? having it *there* but an empty string might be invalid? (can you do just `{ timeframe ... type... }` ? – John Gardner Sep 11 '20 at 23:05
  • and, if the docs are wrong, i'd suggest using the thumbs down in the docs themselves and submitting feedback that they're wrong so they can be fixed – John Gardner Aug 26 '22 at 20:15

1 Answers1

0

Actually, this api-doc provides many examples, you can click any of the example for the request body details.

Take BillingAccountQuery-Modern for example, the request body is as below(you can modify it as per your need):

{
  "type": "Usage",
  "timeframe": "MonthToDate",
  "dataset": {
    "granularity": "Daily",
    "filter": {
      "and": [
        {
          "or": [
            {
              "dimension": {
                "name": "ResourceLocation",
                "operator": "In",
                "values": [
                  "East US",
                  "West Europe"
                ]
              }
            },
            {
              "tag": {
                "name": "Environment",
                "operator": "In",
                "values": [
                  "UAT",
                  "Prod"
                ]
              }
            }
          ]
        },
        {
          "dimension": {
            "name": "ResourceGroup",
            "operator": "In",
            "values": [
              "API"
            ]
          }
        }
      ]
    }
  }
}
Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • But the documentation clearly shows that the `dataset` parameter is not required. Did you see the screenshot in my post? –  Sep 09 '20 at 20:03
  • 1
    @TrevorSullivan, yes, I saw that. Even though it says that the `dataset` is not required, but actually you need at least specify the `dataset` with `granularity`, like this: `{ "dataset": {"granularity": "Daily"}, "type": "ActualCost","timeframe": "BillingMonthToDate"}`. Otherwise, it will throw an error. – Ivan Glasenberg Sep 10 '20 at 02:45
  • @TrevorSullivan, hello, if the answer is helpful, could you please accept it as answer? Thanks. – Ivan Glasenberg Sep 15 '20 at 06:06
  • (actually, randomly this one showed up at the TOP of stackoverflow for me so i thought it was new. If i look at the api docs NOW, the dataset parameter *is* shown as required) – John Gardner Aug 29 '22 at 22:47