我正在使用管理 Rest API 来检索有关某些订阅的计费使用情况的信息。
我已经创建了服务主体并成功调用了 API,但在响应对象中仅返回以下列:
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
我需要示例文档中显示的 PreTaxCost 列。
https://docs.microsoft.com/en-us/rest/api/cost-management/query/usage
更新
我正在接受订阅查询-旧版订阅范围的示例。查看我是否可以像文档中那样检索 PreTaxtColum
但 API 返回了以下错误:
{
"error": {
"code": "BadRequest",
"message": "Model validation failed: Invalid dataset filter; on a QueryFilter one and only one of and/or/not/dimension/tag can be set.\r\nInvalid dataset filter; on a QueryFilter one and only one of and/or/not/dimension/tag can be set.\r\nInvalid dataset filter; on a QueryFilter one and only one of and/or/not/dimension/tag can be set.\r\n\r\n (Request ID: bf5b35cd-739a-47b2-a1fc-6db18be3a71f)"
}
}
我尝试稍微改变示例查询并删除过滤器属性,但它没有返回 PreTaxtCost 列。
我的查询最终是这样的:
{
"type": "Usage",
"timeframe": "MonthToDate",
"dataset": {
"granularity": "Daily"
}
}
确切的答复是:
{
"id": "XXX",
"name": "XXXX",
"type": "Microsoft.CostManagement/query",
"location": null,
"sku": null,
"eTag": null,
"properties": {
"nextLink": null,
"columns": [
{
"name": "UsageDate",
"type": "Number"
},
{
"name": "Currency",
"type": "String"
}
],
"rows": [
[
20200501,
"USD"
],
[
20200502,
"USD"
],
[
20200503,
"USD"
],
[
20200504,
"USD"
],
[
20200505,
"USD"
]
]
}
}
我继续使用SubscriptionQueryGrouping-旧版示例和返回的对象与文档的相同。
那么,有什么意见可以帮助我理解这里的行为吗?文档过时了吗?
答案1
我使用了如下所示的请求主体并且它起作用了。
{
"type": "Usage",
"timeframe": "TheLastMonth",
"dataset": {
"granularity": "None",
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "ResourceGroup"
}
]
}
}
答案2
我遇到了同样的问题,解决方案是使用dimensions
而不是。是的,最后dimension
需要。s