Error message when creating query against Resource Manager, in Azure Monitor Workbook

1.1k views Asked by At

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?

1

There are 1 answers

4
Ivan Glasenberg On

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"
            ]
          }
        }
      ]
    }
  }
}