Azure 报告 API 可帮助查看和管理 Azure 费用。
筛选器可帮助自定义结果以满足需求。
本文介绍如何使用 REST API 返回给定日期范围内的订阅计费详细信息。
GET https://management.azure.com/subscriptions/${subscriptionID}/providers/Microsoft.Billing/billingPeriods/${billingPeriod}/providers/Microsoft.Consumption/usageDetails?$filter=properties/usageEnd ge '${startDate}' AND properties/usageEnd le '${endDate}'
Content-Type: application/json
Authorization: Bearer
生成请求
{subscriptionID}
参数是必需的,用于标识目标订阅。
{billingPeriod}
参数是必需的,用于指定当前计费周期。 BillingPeriod 参数的格式必须设置为没有短划线。 例如,202112
。 如果一个月中的某一天被添加到 BillingPeriod,它会被忽略。
${startDate}
和 ${endDate}
参数对于此示例是必需的,但对于终结点是可选的。 它们以 YYYY-MM-DD 的形式将日期范围指定为字符串。 例如,2018-05-01
和 2018-06-15
。 对于 startDate 和 endDate,必需有短划线。
以下标头是必需的:
请求标头 | 说明 |
---|---|
Content-Type: | 必需。 设置为 application/json 。 |
Authorization: | 必需。 设置为有效的Bearer 访问令牌。 |
响应
系统会返回状态代码 200(正常)以指示一个成功响应,该响应中包含你的帐户的详细费用列表。
{
"value": [
{
"id": "/subscriptions/{$subscriptionID}/providers/Microsoft.Billing/billingPeriods/201702/providers/Microsoft.Consumption/usageDetails/{$detailsID}",
"name": "{$detailsID}",
"type": "Microsoft.Consumption/usageDetails",
"properties": {
"billingPeriodId": "/subscriptions/${subscriptionID}/providers/Microsoft.Billing/billingPeriods/${billingPeriod}",
"invoiceId": "/subscriptions/${subscriptionID}/providers/Microsoft.Billing/invoices/${invoiceID}",
"usageStart": "${startDate}}",
"usageEnd": "${endDate}",
"currency": "USD",
"usageQuantity": "${usageQuantity}",
"billableQuantity": "${billableQuantity}",
"pretaxCost": "${cost}",
"meterId": "${meterID}",
"meterDetails": "${meterDetails}"
}
}
],
"nextLink": "${nextLinkURL}"
}
值中的每一项均表示有关服务使用的详细信息:
响应属性 | 说明 |
---|---|
subscriptionGuid | 订阅的的全局唯一 ID。 |
startDate | 使用开始日期。 |
endDate | 使用结束日期。 |
usageQuantity | 使用数量。 |
billableQuantity | 实际计费数量。 |
pretaxCost | 在适用税前开发票的费用。 |
meterDetails | 有关使用的详细信息。 |
nextLink | 设置时,指定一个 URL 作为详细信息的下一“页”。 当页面为最后一个页面时为空。 |
此示例已经过缩略;请参阅列出使用情况详细信息以了解每个响应字段的完整说明。
其他状态代码指示错误条件。 在这些情况下,响应对象解释请求失败的原因。
{
"error": [
{
"code": "Error type.",
"message": "Error response describing why the operation failed."
}
]
}