可以使用 Azure 计费和消耗 API 以编程方式获取计费帐户的额度余额。
下面显示的示例使用 REST API。 目前,PowerShell 和 Azure CLI 不受支持。
查找有权访问的计费对象信息
GET https://management.chinacloudapi.cn/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
。 例如,如果需要检查“开发”计费对象信息的额度余额,可复制 。 将该值粘贴到某个位置,以便在下一步使用它。
获取额度列表
发出以下请求,将 <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.chinacloudapi.cn/providers/Microsoft.Billing/billingAccounts/<billingAccountId>/billingProfiles/<billingProfileId>/providers/Microsoft.Consumption/lots?api-version=2023-03-01
API 响应返回计费档案中跨所有信用批次的原始信用金额和可用余额。 这包括活动的、过期的,以及具有未来开始日期的积分。 可以通过聚合所有活动额度中的 closedBalance
值来计算可用余额。
{
"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": ""
}
}
]
}
元素名称 |
DESCRIPTION |
creditCurrency |
信用的货币种类。 |
billingCurrency |
用于计费的货币。 |
originalAmount |
额度的原始金额(以美元为单位)。 |
originalAmountInBillingCurrency |
以汇率计费货币的信用额度的原始金额。 |
expirationDate |
额度过期的日期。 |
closedBalance |
截至最后一张发票的余额(以美元为单位)。 |
closedBalanceInBillingCurrency |
最后一张发票时的余额,以计费货币计算,并考虑汇率。 |
reseller |
有关经销商的信息(如果有)。 |
source |
信用额度的来源,例如 Azure 促销额度。 |
startDate |
额度激活的日期。 |
expirationDate |
额度过期的日期。 |
poNumber |
在其上计入了额度的发票的采购订单号。 |
isEstimatedBalance |
显示余额是否为估算。 |
获取影响了额度余额的交易
发出以下请求,将 <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.chinacloudapi.cn/providers/Microsoft.Billing/billingAccounts/<billingAccountID>/billingProfiles/<billingProfileID>/providers/Microsoft.Consumption/events?api-version=2023-03-01&startDate=<date>&endDate=<date>
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": ""
}
}
]
}
元素名称 |
DESCRIPTION |
transactionDate |
交易发生日期。 |
description |
交易说明。 |
adjustments |
针对交易的额度调整。 |
creditExpired |
过期的额度金额。 |
charges |
针对交易的收费。 |
closedBalance |
交易后的余额。 |
eventType |
事务的类型。 |
invoiceNumber |
在其上计收交易费的发票的发票号。 对于挂起的交易,它将为空。 |