您可以使用 Azure 計費和使用量 API,以程式設計方式取得計費帳戶的 Microsoft Azure 使用量承諾 (MACC)。
以下顯示的範例使用 REST API。 目前不支援 PowerShell 和 Azure CLI。 範例輸出適用於 Microsoft 客戶合約,因此 Enterprise 合約的輸出會有所不同。
尋找您可以存取的計費帳戶
GET https://management.azure.com/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
。 將此值貼在某處,以便您在下一個步驟中使用。
取得 Microsoft Azure 使用量承諾的清單
提出下列要求,並以在第一個步驟複製的 name
取代 <billingAccountName>
(9a157b81-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx
)。
GET https://management.azure.com/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 的來源一律為 ConsumptionCommitment。 |
startDate |
MACC 生效的日期。 |
expirationDate |
MACC 失效的日期。 |
您的 MACC 可具有以下其中一種狀態:
- 使用中:MACC 為使用中。 任何適用的支出都會計入您的 MACC 承諾用量。
- 已完成:您已完成 MACC 承諾用量。
- 已過期:MACC 已過期。 如需詳細資訊,請聯絡您的 Microsoft 帳戶小組。
- 已取消:已取消 MACC。 新的 Azure 支出不會計入您的 MACC 承諾用量。
取得影響 MACC 承諾用量的事件
提出下列要求,並以在第一個步驟複製的 name
取代 <billingAccountName>
(5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx
)。 您需要傳遞 startDate 和 endDate 才能取得所需時段內的事件。
GET https://management.azure.com/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。 |