可以使用 Azure 计费和消耗 API 以编程方式获取计费帐户的额度余额。
下面显示的示例使用 REST API。 目前,PowerShell 和 Azure CLI 不受支持。
查找有权访问的计费对象信息
GET https://management.azure.com/providers/Microsoft.Billing/billingAccounts?$expand=billingProfiles&api-version=2019-10-01-preview
API 响应返回一个列表,其中包含计费帐户及其计费对象信息。
{
"value": [
{
"id": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx",
"name": "5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx",
"properties": {
"accountId": "5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"accountStatus": "Active",
"accountType": "Enterprise",
"agreementType": "MicrosoftCustomerAgreement",
"billingProfiles": [
{
"id": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/PBFV-xxxx-xxx-xxx",
"name": "PBFV-xxxx-xxx-xxx",
"properties": {
"address": {
"addressLine1": "AddressLine1",
"city": "City",
"companyName": "CompanyName",
"country": "Country",
"postalCode": "xxxxx",
"region": "Region"
},
"currency": "USD",
"displayName": "Development",
"hasReadAccess": true,
"invoiceDay": 5,
"invoiceEmailOptIn": true
},
"type": "Microsoft.Billing/billingAccounts/billingProfiles"
}
],
"displayName": "Contoso",
"hasReadAccess": true,
},
"type": "Microsoft.Billing/billingAccounts"
}
]
}
使用计费对象信息的 displayName
属性来标识需要检查其额度余额的计费对象信息。 复制计费对象信息的 id
。 例如,如果需要检查“开发”计费对象信息的额度余额,可复制 /providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/PBFV-xxxx-xxx-xxx
。 将该值粘贴到某个位置,以便在下一步使用它。
获取 Azure 额度余额
发出以下请求,将 <billingProfileId>
替换为在第一步复制的 id
(/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/PBFV-xxxx-xxx-xxx
)。
GET https://management.azure.com<billingProfileId>/providers/Microsoft.Consumption/credits/balanceSummary?api-version=2019-10-01
API 响应返回计费对象信息的估算余额和当前余额。
{
"id": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/PBFV-xxxx-xxx-xxx/providers/Microsoft.Consumption/credits/balanceSummary/57c2e8df-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"name": "57c2e8df-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"type": "Microsoft.Consumption/credits/balanceSummary",
"eTag": null,
"properties": {
"balanceSummary": {
"estimatedBalance": {
"currency": "USD",
"value": 996.13
},
"currentBalance": {
"currency": "USD",
"value": 997.87
}
},
"pendingCreditAdjustments": {
"currency": "USD",
"value": 0.0
},
"expiredCredit": {
"currency": "USD",
"value": 0.0
},
"pendingEligibleCharges": {
"currency": "USD",
"value": -1.74
}
}
}
元素名称 |
说明 |
estimatedBalance |
在考虑所有计费交易和挂起交易后估算出的额度金额。 |
currentBalance |
自上次发票以来的额度金额。 它不包括任何挂起交易。 |
pendingCreditAdjustments |
尚未开票的调整项(例如退款)。 |
expiredCredit |
自上次发票以来已过期的额度。 |
pendingEligibleCharges |
尚未开票的符合额度要求的费用。 |
获取额度列表
发出以下请求,将 <billingProfileId>
替换为在第一步复制的 id
(/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/PBFV-xxxx-xxx-xxx
)。
GET https://management.azure.com<billingProfileId>/providers/Microsoft.Consumption/lots?api-version=2019-10-01
API 响应返回计费对象信息的 Azure 额度列表。
{
"value": [
{
"id": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/PBFV-xxxx-xxx-xxx/providers/Microsoft.Consumption/lots/f2ecfd94-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"name": "f2ecfd94-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"type": "Microsoft.Consumption/lots",
"eTag": null,
"properties": {
"originalAmount": {
"currency": "USD",
"value": 500.0
},
"closedBalance": {
"currency": "USD",
"value": 500.0
},
"source": "Azure Promotional Credit",
"startDate": "09/18/2019 21:47:31",
"expirationDate": "09/18/2020 21:47:30",
"poNumber": ""
}
},
{
"id": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/xxxx-xxxx-xxx-xxx/providers/Microsoft.Consumption/lots/4ea40eb5-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"name": "4ea40eb5-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"type": "Microsoft.Consumption/lots",
"eTag": null,
"properties": {
"originalAmount": {
"currency": "USD",
"value": 500.0
},
"closedBalance": {
"currency": "USD",
"value": 497.87
},
"source": "Azure Promotional Credit",
"startDate": "09/18/2019 21:47:31",
"expirationDate": "09/18/2020 21:47:30",
"poNumber": ""
}
}
]
}
元素名称 |
说明 |
originalAmount |
原始额度金额。 |
closedBalance |
自上次发票以来的余额。 |
source |
源,用于定义从何处获得了额度。 |
startDate |
额度激活的日期。 |
expirationDate |
额度过期的日期。 |
poNumber |
在其上计入了额度的发票的采购订单号。 |
获取影响了额度余额的交易
发出以下请求,将 <billingProfileId>
替换为在第一步复制的 id
(providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/PBFV-xxxx-xxx-xxx
)。 需传递 startDate 和 endDate 才能获取所需期间的交易。
GET https://management.azure.com<billingProfileId>/providers/Microsoft.Consumption/events?api-version=2019-10-01&startDate=2018-10-01T00:00:00.000Z&endDate=2019-10-11T12:00:00.000Z?api-version=2019-10-01
API 响应返回影响了计费对象信息的额度余额的所有交易。
{
"value": [
{
"id": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/PBFV-xxxx-xxx-xxx`/providers/Microsoft.Consumption/events/e2032eb5-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"name": "e2032eb5-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"type": "Microsoft.Consumption/events",
"eTag": null,
"properties": {
"transactionDate": "10/11/2019",
"description": "Credit eligible charges as of 10/11/2019",
"newCredit": {
"currency": "USD",
"value": 0.0
},
"adjustments": {
"currency": "USD",
"value": 0.0
},
"creditExpired": {
"currency": "USD",
"value": 0.0
},
"charges": {
"currency": "USD",
"value": -1.74
},
"closedBalance": {
"currency": "USD",
"value": 998.26
},
"eventType": "PendingCharges",
"invoiceNumber": ""
}
},
{
"id": "/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/PBFV-xxxx-xxx-xxx/providers/Microsoft.Consumption/events/381efd80-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"name": "381efd80-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"type": "Microsoft.Consumption/events",
"eTag": null,
"properties": {
"transactionDate": "09/18/2019",
"description": "New credit added on 09/18/2019",
"newCredit": {
"currency": "USD",
"value": 500.0
},
"adjustments": {
"currency": "USD",
"value": 0.0
},
"creditExpired": {
"currency": "USD",
"value": 0.0
},
"charges": {
"currency": "USD",
"value": 0.0
},
"closedBalance": {
"currency": "USD",
"value": 1000.0
},
"eventType": "PendingNewCredit",
"invoiceNumber": ""
}
}
]
}
元素名称 |
说明 |
transactionDate |
交易发生日期。 |
description |
交易说明。 |
adjustments |
针对交易的额度调整。 |
creditExpired |
过期的额度金额。 |
charges |
针对交易的收费。 |
closedBalance |
交易后的余额。 |
eventType |
交易类型。 |
invoiceNumber |
在其上计收交易费的发票的发票号。 对于挂起的交易,它将为空。 |