Query - Usage
查詢所定義範圍的使用量數據。
POST https://management.azure.com/{scope}/providers/Microsoft.CostManagement/query?api-version=2025-03-01
URI 參數
| 名稱 | 位於 | 必要 | 類型 | Description |
|---|---|---|---|---|
|
scope
|
path | True |
string |
與查詢和匯出作業相關聯的範圍。 這包括訂用帳戶範圍的 '/subscriptions/{subscriptionId}/' 、'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' 資源群組範圍、 計費帳戶範圍的 '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' 和 '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department scope, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{EnrollmentAccount 範圍的 enrollmentAccount 範圍,'/providers/Microsoft.Management/managementGroups/{managementGroupId} for Management Group scope, billingProfile 範圍的 '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}'、'/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfileId}/{billingProfileId}/invoiceSections/{invoiceSectionId}' 和 '/providers/Microsoft。Billing/billingAccounts/{billingAccountId}/customers/{customerId}' 特定合作夥伴。 |
|
api-version
|
query | True |
string minLength: 1 |
要用於這項作業的 API 版本。 |
要求本文
| 名稱 | 必要 | 類型 | Description |
|---|---|---|---|
| dataset | True |
具有此查詢中數據的定義。 |
|
| timeframe | True |
提取查詢數據的時間範圍。 如果為 custom,則必須提供特定的時間週期。 |
|
| type | True |
查詢的類型。 |
|
| timePeriod |
有提取查詢數據的時間週期。 |
回應
| 名稱 | 類型 | Description |
|---|---|---|
| 200 OK |
Azure 作業已順利完成。 |
|
| 204 No Content |
此要求沒有內容可傳送,但標頭可能很有用。 |
|
| Other Status Codes |
未預期的錯誤回應。 |
安全性
azure_auth
Azure Active Directory OAuth2 Flow。
類型:
oauth2
Flow:
implicit
授權 URL:
https://login.microsoftonline.com/common/oauth2/authorize
範圍
| 名稱 | Description |
|---|---|
| user_impersonation | 模擬您的用戶帳戶 |
範例
BillingAccountQuery-Legacy
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"timeframe": "MonthToDate"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/70664866/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
20180331,
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
20180331,
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
20180331,
"USD"
],
[
0.16677720329728665,
"gs-stms-dev",
20180331,
"USD"
]
]
}
}
BillingAccountQuery-MCA
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"timeframe": "MonthToDate"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
20180331,
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
20180331,
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
20180331,
"USD"
],
[
0.16677720329728665,
"gs-stms-dev",
20180331,
"USD"
]
]
}
}
BillingAccountQueryGrouping-Legacy
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"granularity": "None",
"grouping": [
{
"name": "ResourceGroup",
"type": "Dimension"
}
]
},
"timeframe": "TheLastMonth"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/70664866/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
"USD"
]
]
}
}
BillingAccountQueryGrouping-MCA
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"granularity": "None",
"grouping": [
{
"name": "ResourceGroup",
"type": "Dimension"
}
]
},
"timeframe": "TheLastMonth"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
"USD"
]
]
}
}
BillingProfileQuery-MCA
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"timeframe": "MonthToDate"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
20180331,
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
20180331,
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
20180331,
"USD"
],
[
0.16677720329728665,
"gs-stms-dev",
20180331,
"USD"
]
]
}
}
BillingProfileQueryGrouping-MCA
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"granularity": "None",
"grouping": [
{
"name": "ResourceGroup",
"type": "Dimension"
}
]
},
"timeframe": "TheLastMonth"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
"USD"
]
]
}
}
CustomerQuery-MCA
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/customers/5678/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"timeframe": "MonthToDate"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/customers/5678/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/customers/5678/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
20180331,
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
20180331,
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
20180331,
"USD"
],
[
0.16677720329728665,
"gs-stms-dev",
20180331,
"USD"
]
]
}
}
CustomerQueryGrouping-MCA
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/customers/5678/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"granularity": "None",
"grouping": [
{
"name": "ResourceGroup",
"type": "Dimension"
}
]
},
"timeframe": "TheLastMonth"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/customers/5678/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/customers/5678/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
"USD"
]
]
}
}
DepartmentQuery-Legacy
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/100/departments/123/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"timeframe": "MonthToDate"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/70664866/departments/123/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/departments/123/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
20180331,
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
20180331,
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
20180331,
"USD"
],
[
0.16677720329728665,
"gs-stms-dev",
20180331,
"USD"
]
]
}
}
DepartmentQueryGrouping-Legacy
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/100/departments/123/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"granularity": "None",
"grouping": [
{
"name": "ResourceGroup",
"type": "Dimension"
}
]
},
"timeframe": "TheLastMonth"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/70664866/departments/123/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/departments/123/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
"USD"
]
]
}
}
EnrollmentAccountQuery-Legacy
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/100/enrollmentAccounts/456/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"timeframe": "MonthToDate"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/70664866/enrollmentAccounts/456/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/enrollmentAccounts/456/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
20180331,
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
20180331,
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
20180331,
"USD"
],
[
0.16677720329728665,
"gs-stms-dev",
20180331,
"USD"
]
]
}
}
EnrollmentAccountQueryGrouping-Legacy
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/100/enrollmentAccounts/456/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"granularity": "Daily",
"grouping": [
{
"name": "ResourceGroup",
"type": "Dimension"
}
]
},
"timeframe": "TheLastMonth"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/70664866/enrollmentAccounts/456/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/enrollmentAccounts/456/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
20180331,
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
20180331,
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
20180331,
"USD"
]
]
}
}
InvoiceSectionQuery-MCA
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"timeframe": "MonthToDate"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
20180331,
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
20180331,
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
20180331,
"USD"
],
[
0.16677720329728665,
"gs-stms-dev",
20180331,
"USD"
]
]
}
}
InvoiceSectionQueryGrouping-MCA
範例要求
POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"granularity": "None",
"grouping": [
{
"name": "ResourceGroup",
"type": "Dimension"
}
]
},
"timeframe": "TheLastMonth"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/12345:6789/billingProfiles/13579/invoiceSections/9876/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
"USD"
]
]
}
}
ManagementGroupQuery-Legacy
範例要求
POST https://management.azure.com/providers/Microsoft.Management/managementGroups/MyMgId/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"timeframe": "MonthToDate"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Management/managementGroups/MyMgId/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Management/managementGroups/MyMgId/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
19.545363672276512,
"JapanUnifia-Trial",
20180331,
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
20180331,
"USD"
],
[
20.35941656262545,
"VSTSHOL-1595322048000",
20180331,
"USD"
],
[
0.16677720329728665,
"gs-stms-dev",
20180331,
"USD"
]
]
}
}
ManagementGroupQueryGrouping-Legacy
範例要求
POST https://management.azure.com/providers/Microsoft.Management/managementGroups/MyMgId/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"granularity": "None",
"grouping": [
{
"name": "ResourceGroup",
"type": "Dimension"
}
]
},
"timeframe": "TheLastMonth"
}
範例回覆
{
"name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"type": "microsoft.costmanagement/Query",
"id": "/providers/Microsoft.Management/managementGroups/MyMgId/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": "https://management.azure.com/providers/Microsoft.Management/managementGroups/MyMgId/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
"rows": [
[
20.35941656262545,
"VSTSHOL-1595322048000",
20180331,
"USD"
],
[
173.41979241290323,
"RVIIOT-TRIAL",
20180331,
"USD"
],
[
19.545363672276512,
"JapanUnifia-Trial",
20180331,
"USD"
]
]
}
}
ResourceGroupQuery-Legacy
範例要求
POST https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ScreenSharingTest-peer/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"timeframe": "MonthToDate"
}
範例回覆
{
"name": "9af9459d-441d-4055-9ed0-83d4c4a363fb",
"type": "microsoft.costmanagement/Query",
"id": "/subscriptions/55312978-ba1b-415c-9304-c4b9c43c0481/resourcegroups/ScreenSharingTest-peer/providers/Microsoft.CostManagement/Query/9af9459d-441d-4055-9ed0-83d4c4a363fb",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": null,
"rows": [
[
2.10333307059661,
"ScreenSharingTest-peer",
20180417,
"USD"
],
[
20.10333307059661,
"ScreenSharingTest-peer",
20180418,
"USD"
]
]
}
}
ResourceGroupQueryGrouping-Legacy
範例要求
POST https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ScreenSharingTest-peer/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"granularity": "Daily",
"grouping": [
{
"name": "ResourceType",
"type": "Dimension"
}
]
},
"timeframe": "TheLastMonth"
}
範例回覆
{
"name": "9af9459d-441d-4055-9ed0-83d4c4a363fb",
"type": "microsoft.costmanagement/Query",
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/ScreenSharingTest-peer/providers/Microsoft.CostManagement/Query/9af9459d-441d-4055-9ed0-83d4c4a363fb",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceType",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": null,
"rows": [
[
2.10333307059661,
"Microsoft.SqlServer",
20180417,
"USD"
],
[
20.10333307059661,
"Microsoft.Compute",
20180418,
"USD"
]
]
}
}
SubscriptionQuery-Legacy
範例要求
POST https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"filter": {
"and": [
{
"or": [
{
"dimensions": {
"name": "ResourceLocation",
"operator": "In",
"values": [
"East US",
"West Europe"
]
}
},
{
"tags": {
"name": "Environment",
"operator": "In",
"values": [
"UAT",
"Prod"
]
}
}
]
},
{
"dimensions": {
"name": "ResourceGroup",
"operator": "In",
"values": [
"API"
]
}
}
]
},
"granularity": "Daily"
},
"timeframe": "MonthToDate"
}
範例回覆
{
"name": "55312978-ba1b-415c-9304-cfd9c43c0481",
"type": "microsoft.costmanagement/Query",
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/Query/00000000-0000-0000-0000-000000000000",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": null,
"rows": [
[
2.10333307059661,
"ScreenSharingTest-peer",
20180331,
"USD"
],
[
218.68795741935486,
"Ict_StratAndPlan_GoldSprova_Prod",
20180331,
"USD"
],
[
0.14384913581657052,
"ssbciotelement01",
20180401,
"USD"
],
[
0.009865586851323632,
"ict_stratandplan_goldsprova_prod",
20180429,
"USD"
]
]
}
}
SubscriptionQueryGrouping-Legacy
範例要求
POST https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/query?api-version=2025-03-01
{
"type": "Usage",
"dataset": {
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"granularity": "None",
"grouping": [
{
"name": "ResourceGroup",
"type": "Dimension"
}
]
},
"timeframe": "TheLastMonth"
}
範例回覆
{
"name": "55312978-ba1b-415c-9304-cfd9c43c0481",
"type": "microsoft.costmanagement/Query",
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/Query/00000000-0000-0000-0000-000000000000",
"properties": {
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"nextLink": null,
"rows": [
[
0.009865586851323632,
"Ict_StratAndPlan_GoldSprova_Prod_0",
"USD"
],
[
218.68795741935486,
"Ict_StratAndPlan_GoldSprova_Prod_1",
"USD"
],
[
2.10333307059661,
"ScreenSharingTest-peer1",
"USD"
],
[
0.14384913581657052,
"Ssbciotelement01",
"USD"
]
]
}
}
定義
| 名稱 | Description |
|---|---|
|
Error |
錯誤的詳細數據。 |
|
Error |
錯誤回應表示服務無法處理傳入要求。 錯誤訊息中會提供原因。 \n\n一些錯誤回應:\n\n * 429 TooManyRequests - 請求被限速。 等候 「x-ms-ratelimit-microsoft.consumption-retry-after」 標頭中指定的時間後重試。 \n\n * 503 服務不可用 - 服務暫時無法使用。 等候 「Retry-After」 標頭中指定的時間後重試。 |
|
Export |
匯出的類型。 請注意,『Usage』 相當於 『ActualCost』,而且適用於尚未提供服務保留費用或攤銷數據的導出。 |
|
Function |
要使用的聚合函數名稱。 |
|
Granularity |
匯出中的數據列粒度。 大部分情況下目前支援「每日」。 |
|
Query |
要用於查詢的匯總表達式。 |
|
Query |
QueryColumn 屬性 |
|
Query |
報告中欄位的類型。 |
|
Query |
要在查詢中使用的比較表達式。 |
|
Query |
查詢中存在的數據定義。 |
|
Query |
查詢中數據集的組態。 |
|
Query |
查詢的定義。 |
|
Query |
要用於導出的篩選表達式。 |
|
Query |
要用於查詢中的依表示式分組。 |
|
Query |
要用於比較的運算符。 |
|
Query |
查詢的結果。 它包含群組和匯總下所列的所有數據行。 |
|
Query |
用於提取查詢數據的開始和結束日期。 |
|
Timeframe |
提取匯出數據的時間範圍。 如果為 custom,則必須提供特定的時間週期。 |
ErrorDetails
錯誤的詳細數據。
| 名稱 | 類型 | Description |
|---|---|---|
| code |
string |
錯誤碼。 |
| message |
string |
錯誤訊息,指出作業失敗的原因。 |
ErrorResponse
錯誤回應表示服務無法處理傳入要求。 錯誤訊息中會提供原因。 \n\n一些錯誤回應:\n\n * 429 TooManyRequests - 請求被限速。 等候 「x-ms-ratelimit-microsoft.consumption-retry-after」 標頭中指定的時間後重試。 \n\n * 503 服務不可用 - 服務暫時無法使用。 等候 「Retry-After」 標頭中指定的時間後重試。
| 名稱 | 類型 | Description |
|---|---|---|
| error |
錯誤的詳細數據。 |
ExportType
匯出的類型。 請注意,『Usage』 相當於 『ActualCost』,而且適用於尚未提供服務保留費用或攤銷數據的導出。
| 值 | Description |
|---|---|
| Usage | |
| ActualCost | |
| AmortizedCost | |
| FocusCost | |
| PriceSheet | |
| ReservationTransactions | |
| ReservationRecommendations | |
| ReservationDetails |
FunctionType
要使用的聚合函數名稱。
| 值 | Description |
|---|---|
| Sum |
GranularityType
匯出中的數據列粒度。 大部分情況下目前支援「每日」。
| 值 | Description |
|---|---|
| Daily | |
| Monthly |
QueryAggregation
要用於查詢的匯總表達式。
| 名稱 | 類型 | Description |
|---|---|---|
| function |
要使用的聚合函數名稱。 |
|
| name |
string |
要匯總的數據行名稱。 |
QueryColumn
QueryColumn 屬性
| 名稱 | 類型 | Description |
|---|---|---|
| name |
string |
數據行的名稱。 |
| type |
string |
數據行的類型。 |
QueryColumnType
報告中欄位的類型。
| 值 | Description |
|---|---|
| TagKey |
與成本數據相關聯的標記。 |
| Dimension |
成本數據的維度。 |
QueryComparisonExpression
要在查詢中使用的比較表達式。
| 名稱 | 類型 | Description |
|---|---|---|
| name |
string |
要用於比較的數據行名稱。 |
| operator |
要用於比較的運算符。 |
|
| values |
string[] |
要用於比較的值陣列 |
QueryDataset
查詢中存在的數據定義。
| 名稱 | 類型 | Description |
|---|---|---|
| aggregation |
<string,
Query |
要用於查詢的匯總表示式字典。 字典中每個專案的索引鍵是匯總數據行的別名。 Query 最多可以有 2 個聚合子句。 |
| configuration |
具有匯出中數據的組態資訊。 如果提供匯總和群組,將會忽略組態。 |
|
| filter |
要在查詢中使用的篩選條件表達式。 請參閱我們的查詢 API REST 文件,瞭解如何正確設置篩檢程式的格式。 |
|
| granularity |
查詢中數據列的數據粒度。 |
|
| grouping |
要用於查詢的依表示式分組陣列。 Query 最多可以有 2 個 group by 子句。 |
QueryDatasetConfiguration
查詢中數據集的組態。
| 名稱 | 類型 | Description |
|---|---|---|
| columns |
string[] |
要包含在查詢中的數據行名稱陣列。 允許任何有效的查詢數據行名稱。 如果未提供,則查詢會包含所有數據行。 |
QueryDefinition
查詢的定義。
| 名稱 | 類型 | Description |
|---|---|---|
| dataset |
具有此查詢中數據的定義。 |
|
| timePeriod |
有提取查詢數據的時間週期。 |
|
| timeframe |
提取查詢數據的時間範圍。 如果為 custom,則必須提供特定的時間週期。 |
|
| type |
查詢的類型。 |
QueryFilter
要用於導出的篩選表達式。
| 名稱 | 類型 | Description |
|---|---|---|
| and |
邏輯 「AND」 表達式。 必須至少有2個專案。 |
|
| dimensions |
具有維度的比較表達式 |
|
| or |
邏輯 「OR」 表達式。 必須至少有2個專案。 |
|
| tags |
具有標記的比較表達式 |
QueryGrouping
要用於查詢中的依表示式分組。
| 名稱 | 類型 | Description |
|---|---|---|
| name |
string |
要分組的數據行名稱。 |
| type |
具有要分組的數據行類型。 |
QueryOperatorType
要用於比較的運算符。
| 值 | Description |
|---|---|
| In |
QueryResult
查詢的結果。 它包含群組和匯總下所列的所有數據行。
| 名稱 | 類型 | Description |
|---|---|---|
| eTag |
string |
資源的 ETag。 |
| id |
string |
資源標識碼。 |
| location |
string |
資源的位置。 |
| name |
string |
資源名稱。 |
| properties.columns |
數據列陣列 |
|
| properties.nextLink |
string |
結果下一頁的連結(url)。 |
| properties.rows |
Rows[] |
數據列陣列 |
| sku |
string |
資源的 SKU。 |
| tags |
object |
資源標籤。 |
| type |
string |
資源類型。 |
QueryTimePeriod
用於提取查詢數據的開始和結束日期。
| 名稱 | 類型 | Description |
|---|---|---|
| from |
string (date-time) |
要從中提取數據的開始日期。 |
| to |
string (date-time) |
要提取數據的結束日期。 |
TimeframeType
提取匯出數據的時間範圍。 如果為 custom,則必須提供特定的時間週期。
| 值 | Description |
|---|---|
| MonthToDate | |
| BillingMonthToDate | |
| TheLastMonth | |
| TheLastBillingMonth | |
| WeekToDate | |
| Custom | |
| TheCurrentMonth |