Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Analyze and reduce Azure cloud costs by right-sizing resources, reservations, and spending policies
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
cost-query/request-body-schema.md
1# Cost Management Query API — Request Body Schema23Schema for the [Cost Management Query API](https://learn.microsoft.com/en-us/rest/api/cost-management/query/usage).45## Request Body Structure67```json8{9"type": "<report-type>",10"timeframe": "<timeframe>",11"timePeriod": { "from": "2024-01-01T00:00:00Z", "to": "2024-01-31T23:59:59Z" },12"dataset": {13"granularity": "<granularity>",14"aggregation": { "<alias>": { "name": "<column>", "function": "<function>" } },15"grouping": [{ "type": "<column-type>", "name": "<column-name>" }],16"filter": { "<filter-expression>" },17"sorting": [{ "direction": "<direction>", "name": "<column>" }]18}19}20```2122## Top-Level Fields2324| Field | Type | Required | Description |25|-------|------|----------|-------------|26| `type` | string | Yes | `ActualCost`, `AmortizedCost`, or `Usage` |27| `timeframe` | string | Yes | Predefined or `Custom` time window |28| `timePeriod` | object | Conditional | Required when `timeframe` is `Custom`. Contains `from`/`to` ISO 8601 dates. |29| `dataset` | object | Yes | Defines granularity, aggregation, grouping, filtering, sorting |3031### Timeframe Values3233`WeekToDate` · `MonthToDate` · `BillingMonthToDate` · `YearToDate` · `TheLastWeek` · `TheLastMonth` · `TheLastBillingMonth` · `TheLastYear` · `TheLast7Days` · `TheLast3Months` · `Custom`3435## Dataset Fields3637### Granularity3839| Value | Max Range | Description |40|-------|-----------|-------------|41| `None` | 12 months | Aggregated total, no date breakdown |42| `Daily` | 31 days | Day-by-day breakdown |43| `Monthly` | 12 months | Month-by-month breakdown |4445### Aggregation4647```json48"aggregation": { "totalCost": { "name": "Cost", "function": "Sum" } }49```5051| Field | Required | Description |52|-------|----------|-------------|53| `<alias>` (key) | Yes | Output column alias (e.g., `totalCost`) |54| `name` | Yes | Source column: `Cost`, `PreTaxCost`, or `UsageQuantity` |55| `function` | Yes | `Sum` (only supported function for cost queries) |5657### Grouping5859```json60"grouping": [61{ "type": "Dimension", "name": "ServiceName" },62{ "type": "TagKey", "name": "Environment" }63]64```6566- `type`: `Dimension` (built-in) or `TagKey` (resource tag)67- Maximum **2** GroupBy dimensions per query. No duplicates.6869### Filter7071Filter expressions restrict which cost records are included. Filters support logical operators (`and`, `or`, `not`) and comparison operators on dimensions or tags.7273#### Filter Expression Structure7475```json76"filter": {77"and": [78{79"dimensions": {80"name": "ResourceGroupName",81"operator": "In",82"values": ["rg-prod", "rg-staging"]83}84},85{86"not": {87"tags": {88"name": "Environment",89"operator": "Equal",90"values": ["dev"]91}92}93}94]95}96```9798#### Logical Operators99100| Operator | Description | Children |101|----------|-------------|----------|102| `and` | All child expressions must match. | 2 or more expressions. |103| `or` | Any child expression must match. | 2 or more expressions. |104| `not` | Negates a single child expression. | Exactly 1 expression. |105106> ⚠️ **Warning:** `and` and `or` must contain at least 2 child expressions. `not` must contain exactly 1.107108#### Comparison Operators (ComparisonOperator Enum)109110| Operator | Description | Example |111|----------|-------------|---------|112| `In` | Value is in the provided list. Supports multiple values. | `"values": ["vm", "storage"]` |113| `Equal` | Exact match against a single value. | `"values": ["production"]` |114| `Contains` | String contains the specified substring. | `"values": ["prod"]` |115| `LessThan` | Numeric less-than comparison. | `"values": ["100"]` |116| `GreaterThan` | Numeric greater-than comparison. | `"values": ["0"]` |117| `NotEqual` | Value does not match the specified value. | `"values": ["dev"]` |118119#### Filter Target Types120121| Target | Description |122|--------|-------------|123| `dimensions` | Filter on built-in dimensions (e.g., `ResourceGroupName`, `ServiceName`). |124| `tags` | Filter on Azure resource tags (e.g., `Environment`, `CostCenter`). |125126### Sorting127128```json129"sorting": [130{ "direction": "Descending", "name": "Cost" }131]132```133134| Field | Type | Required | Description |135|-------|------|----------|-------------|136| `direction` | string | Yes | `Ascending` or `Descending`. |137| `name` | string | Yes | Column name to sort by (must be present in aggregation or grouping). |138139## Response Structure140141```json142{143"id": "<query-id>",144"name": "<query-name>",145"type": "Microsoft.CostManagement/query",146"properties": {147"nextLink": "<url-for-next-page-or-null>",148"columns": [149{ "name": "Cost", "type": "Number" },150{ "name": "ServiceName", "type": "String" },151{ "name": "UsageDate", "type": "Number" },152{ "name": "Currency", "type": "String" }153],154"rows": [155[123.45, "Virtual Machines", 20240115, "USD"],156[67.89, "Storage", 20240115, "USD"]157]158}159}160```161162| Field | Type | Description |163|-------|------|-------------|164| `columns` | array | Array of column definitions with `name` and `type`. |165| `columns[].name` | string | Column name. |166| `columns[].type` | string | Data type: `Number` or `String`. |167| `rows` | array | Array of row arrays. Values ordered to match `columns`. |168| `nextLink` | string | URL for next page of results, or `null` if no more pages. |169170> 💡 **Tip:** `UsageDate` is returned as a number in `YYYYMMDD` format (e.g., `20240115`) when granularity is `Daily` or `Monthly`.171