可以使用 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。 例如,如果要检查 开发 计费配置文件的信用余额,则复制 /providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx_xxxx-xx-xx/billingProfiles/PBFV-xxxx-xxx-xxx。 将该值粘贴到某个位置,以便在下一步使用它。
获取信用额度列表
发出以下请求,将 <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 |
对交易进行计费的发票的发票编号。 对于挂起的交易,它将为空。 |