可以使用 Azure Billing 和 Consumption API 以编程方式获取计费帐户的 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。 将该值粘贴到某个位置,以便在下一步使用它。
获取 MACC 列表
发出以下请求。 将<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"
}
}
]
}
| 元素名称 |
Description |
purchasedDate |
购买 MACC 的日期。 |
status |
您承诺的状态。 |
originalAmount |
原始承诺金额。 |
closedBalance |
自上次发票以来的剩余承诺。 |
source |
协议源。 对于 MACC,源始终是ConsumptionCommitment。 |
startDate |
MACC 处于活动状态的日期。 |
expirationDate |
MACC 过期的日期。 |
MACC 可以具有以下状态之一:
-
Active。 MACC 当前生效。 符合条件的Azure支出有助于履行承诺。
-
Complete。 你完全满足 MACC 金额。 无需执行进一步操作。
-
Expired。 MACC 结束日期已过,而承诺尚未完全实现。 有关详细信息,请联系Microsoft 帐户团队。
-
Canceled。 MACC 在结束日期之前终止。 新的Azure支出对 MACC 没有贡献。 有关详细信息,请联系Microsoft 帐户团队。
获取可能影响 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"
}
}
]
}
| 元素名称 |
Description |
billingProfileId |
与该事件相关的计费配置文件的唯一标识符。 |
billingProfileDisplayName |
与事件相关的计费配置文件的显示名称。 |
lotId |
MACC 的唯一标识符。 |
lotSource |
协议的批量来源。 该值适用于 ConsumptionCommitment MACC。 |
transactionDate |
事件发生的日期。 |
description |
事件的说明。 |
charges |
MACC 递减量。 |
closedBalance |
事件后剩余余额。 |
eventType |
事件类型。 仅支持 SettledCharges 事件的 MACC。 |
invoiceNumber |
其费用递减 MACC 的发票的唯一 ID。 |