可以使用 Azure 计费和消耗 API 以编程方式获取你的计费帐户的 Azure 使用量承诺 (MACC)。
下面显示的示例使用 REST API。 目前,PowerShell 和 Azure CLI 不受支持。 示例输出适用于 Microsoft 客户协议,因此针对企业协议的输出与此不同。
查找你有权访问的计费帐户
GET https://management.chinacloudapi.cn/providers/Microsoft.Billing/billingAccounts?api-version=2020-05-01
API 响应会返回计费帐户的列表。
{
"value": [
{
"id": "/providers/Microsoft.Billing/billingAccounts/9a157b81-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx",
"name": "9a157b81-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx",
"type": "Microsoft.Billing/billingAccounts",
"properties": {
"displayName": "Contoso",
"agreementType": "MicrosoftCustomerAgreement",
"accountStatus": "Active",
"accountType": "Enterprise",
"hasReadAccess": true,
}
},
{
"id": "/providers/Microsoft.Billing/billingAccounts/9a12f056-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx",
"name": "9a12f056-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx",
"type": "Microsoft.Billing/billingAccounts",
"properties": {
"displayName": "Kayla Lewis",
"agreementType": "MicrosoftCustomerAgreement",
"accountStatus": "Active",
"accountType": "Individual",
"hasReadAccess": true,
}
}
]
}
使用计费帐户的 displayName
属性来标识要跟踪其 MACC 的计费帐户。 复制计费帐户的 name
。 例如,如果想要跟踪 Contoso 计费帐户的 MACC,则需要复制 9a157b81-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx
。 将该值粘贴到某个位置,以便在下一步使用它。
获取 Azure 使用量承诺的列表
发出以下请求,将 <billingAccountName>
替换为在第一步复制的 name
(9a157b81-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx
)。
GET https://management.chinacloudapi.cn/providers/Microsoft.Billing/billingAccounts/<billingAccountName>/providers/Microsoft.Consumption/lots?api-version=2021-05-01&$filter=source%20eq%20%27ConsumptionCommitment%27
API 响应会返回你的计费帐户的 MACC 的列表。
{
"value": [
{
"id": "/providers/Microsoft.Billing/billingAccounts/9a157b81-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/providers/Microsoft.Consumption/lots/G2021032459206000XXXX",
"name": "G2021032459206000XXXX",
"type": "Microsoft.Consumption/lots",
"eTag": null,
"properties": {
"purchasedDate": "2021-03-24T16:26:46.0000000Z",
"status": "Active",
"originalAmount": {
"currency": "USD",
"value": 10000.0
},
"closedBalance": {
"currency": "USD",
"value": 9899.42
},
"source": "ConsumptionCommitment",
"startDate": "2021-03-01T00:00:00.0000000Z",
"expirationDate": "2024-02-28T00:00:00.0000000Z"
}
},
{
"id": "/providers/Microsoft.Billing/billingAccounts/9a157b81-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/providers/Microsoft.Consumption/lots/G1011082459206000XXXX",
"name": "G1011082459206000XXXX",
"type": "Microsoft.Consumption/lots",
"eTag": null,
"properties": {
"purchasedDate": "2021-03-24T16:26:46.0000000Z",
"status": "Complete",
"originalAmount": {
"currency": "USD",
"value": 10000.0
},
"closedBalance": {
"currency": "USD",
"value": 0.00
},
"source": "ConsumptionCommitment",
"startDate": "2020-03-01T00:00:00.0000000Z",
"expirationDate": "2021-02-28T00:00:00.0000000Z"
}
}
]
}
元素名称 |
说明 |
purchasedDate |
购买 MACC 的日期。 |
status |
你的承诺的状态。 |
originalAmount |
原始承诺金额。 |
closedBalance |
自上次发票之后的剩余承诺金额。 |
source |
对于 MACC,source 将始终为 ConsumptionCommitment。 |
startDate |
MACC 的激活日期。 |
expirationDate |
MACC 的到期日期。 |
你的 MACC 可能具有下列状态之一:
- 活动:MACC 处于活动状态。 任何合格支出都会计入你的 MACC 承诺。
- 已完成:你已完成你的 MACC 承诺。
- 已过期:MACC 已过期。 有关详细信息,请与你的 Microsoft 帐户团队联系。
- 已取消:MACC 已被取消。 新的 Azure 支出不会计入你的 MACC 承诺。
获取影响了 MACC 承诺的事件
发出以下请求,将 <billingAccountName>
替换为在第一步复制的 name
(5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx
)。 需要传递 startDate 和 endDate 来获取所需期间内的事件。
GET https://management.chinacloudapi.cn/providers/Microsoft.Billing/billingAccounts/<billingAccountName>/providers/Microsoft.Consumption/events?api-version=2021-05-01&startDate=<startDate>&endDate=<endDate>&$filter=lotsource%20eq%20%27ConsumptionCommitment%27
API 响应会返回影响了你的 MACC 承诺的所有事件。
{
"value": [
{
"id": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/providers/Microsoft.Consumption/events/103axxxx-2c25-7xx3-f2a0-ad9a3f1c91xx",
"name": "103axxxx-2c25-7xx3-f2a0-ad9a3f1c91xx",
"type": "Microsoft.Consumption/events",
"eTag": null,
"properties": {
"billingProfileId": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/SWFF-DVM4-XXX-XXX",
"billingProfileDisplayName": "Finance",
"lotId": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/providers/Microsoft.Consumption/lots/G2021032459206000XXXX",
"lotSource": "ConsumptionCommitment",
"transactionDate": "2021-05-05T00:09:13.0000000Z",
"description": "Balance after invoice T00075XXXX",
"charges": {
"currency": "USD",
"value": -100.0
},
"closedBalance": {
"currency": "USD",
"value": 9899.71
},
"eventType": "SettledCharges",
"invoiceNumber": "T00075XXXX"
}
},
{
"id": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/providers/Microsoft.Consumption/events/203axxxx-2c25-7xx3-f2a0-ad9a3f1c91xx",
"name": "203axxxx-2c25-7xx3-f2a0-ad9a3f1c91xx",
"type": "Microsoft.Consumption/events",
"eTag": null,
"properties": {
"billingProfileId": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/SWFF-DVM4-XXX-XXX",
"billingProfileDisplayName": "Engineering",
"lotId": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/providers/Microsoft.Consumption/lots/G2021032459206000XXXX",
"lotSource": "ConsumptionCommitment",
"transactionDate": "2021-04-05T00:09:13.0000000Z",
"description": "Balance after invoice T00074XXXX",
"charges": {
"currency": "USD",
"value": -0.29
},
"closedBalance": {
"currency": "USD",
"value": 9999.71
},
"eventType": "SettledCharges",
"invoiceNumber": "T00074XXXX"
}
}
]
}
元素名称 |
说明 |
billingProfileId |
发生的事件对应的计费对象信息的唯一标识符。 |
billingProfileDisplayName |
发生的事件对应的计费对象信息的显示名称。 |
lotId |
MACC 的唯一标识符。 |
lotSource |
它将是 MACC 的 ConsumptionCommitment。 |
transactionDate |
事件的发生日期。 |
description |
事件的说明。 |
charges |
MACC 减量金额。 |
closedBalance |
发生此事件后的余额。 |
eventType |
MACC 仅支持 SettledCharges 事件。 |
invoiceNumber |
其收费对 MACC 造成了减量的发票的唯一 ID。 |