gpt4 book ai didi

Azure:通过REST API获取单个资源的当前余额

转载 作者:行者123 更新时间:2023-12-02 07:34:05 26 4
gpt4 key购买 nike

我希望通过 Azure 的 REST API 获取给定资源(不是整个订阅或资源组)当前期间在 MS Azure 上花费的实时当前金额(例如:到目前为止我们已花费 X$本月在此资源上)。我已经深入研究了 Billing API 和一般 REST API 文档(以及它们的 Node.js SDK),但我找不到任何似乎可以做到这一点的内容。

有人做过类似的事情吗?任何帮助将不胜感激。

最佳答案

请注意此文档:Azure consumption API overview ,这里显示您可以使用带有过滤器的 Usage Details API 来获取您想要的内容:

  • Filtering - Trim your API result set down to a smaller set of usage detail records using the following filters:
    • Usage end / usage start
    • Resource Group
    • Resource Name

这是 API 的格式:

GET https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?$expand={$expand}&$filter={$filter}&$skiptoken={$skiptoken}&$top={$top}&$apply={$apply}&api-version=2019-01-01

对于{scope},除了可以使用“/subscriptions/{subscriptionId}/”作为订阅范围外,还可以使用“/providers/Microsoft.Billing/billingAccounts/{billingAccountId}”作为订阅范围计费账号范围等,更多详情引用这个doc .

使用$filter={$filter}可以实现你想要的(访问特定资源),这里提供我的API可以供你引用:

GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/usageDetails?$expand=meterDetails,additionalProperties&$filter=properties/usageEnd ge '2019-01-1' AND properties/usageEnd le '2019-05-22' AND properties/instanceName eq '{instanceName}'&$top=30&api-version=2019-01-01

eq means equals, ge means greater or equal, le means less or equal, and the instanceNmae means your specific resource name that the usage is about.

关于Azure:通过REST API获取单个资源的当前余额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56247096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com