Azure成本管理API不遵循所需的日期过滤器。

huangapple go评论64阅读模式
英文:

Azure cost management API does not respect the desired date filters

问题

我正在编写一个.NET程序来检索订阅的使用成本。HTTP请求的结构如下:

https://management.azure.com/subscriptions/(在这里输入订阅号)/providers/Microsoft.Consumption/usageDetails?startDate=2023-06-01&endDate=2023-06-02&api-version=2021-10-01

问题是:无论我在“startDate”和“endDate”中输入什么日期,它总是检索到当前月份从月初到今天的所有成本数据。例如:如果今天是7月15日,该请求会获取从7月1日到7月15日的所有成本数据,而不考虑我指定的日期间隔。

我做错了什么?
非常感谢您对这位伪装的灵魂提供的任何反馈。

英文:

I am writing a program in .NET to retrieve the usage cost of a subscription. The structure of the HTTP request is this:

https://management.azure.com/subscriptions/(here_goes_the_subscription_number)/providers/Microsoft.Consumption/usageDetails?startDate=2023-06-01&endDate=2023-06-02&api-version=2021-10-01

The problem is: No matter what dates I put in the "startDate" and "endDate", it always retrieves all the cost data of the current month from day 1 of the month. For example: If today is July 15, the request brings to me all the cost data from July 1 to July 15, regardless of the date interval I specified.

What am I doing wrong?
Thank you very much for any feedback you could provide to this tortured soul in disguise.

答案1

得分: 1

I agree with @Anupam Chand, API response differs based on the type of subscription that you are currently using.

To retrieve the usage cost of a subscription within a specific duration,
you need to include $filter in the query, which works only with Enterprise Agreement (EA) or a pay-as-you-go subscriptions and is not supported by
Microsoft Customer Agreements subscription.

If you have Enterprise Agreement (EA) or a pay-as-you-go subscription, you can make use of the following query by including $filter to retrieve the usage cost of a subscription within a specific duration:

GET https://management.azure.com/subscriptions/<subID>/providers/Microsoft.Consumption/usageDetails?$filter=properties/usageStart ge '2023-06-01' and properties/usageEnd le '2023-06-02'&$top=1000&api-version=2019-10-01

I have one Azure account with a pay-as-you-go subscription like below:

Azure成本管理API不遵循所需的日期过滤器。

When I ran the following query by including $filter with different dates, I got different results successfully like this:

QUERY 1:

GET https://management.azure.com/subscriptions/<subID>/providers/Microsoft.Consumption/usageDetails?$filter=properties/usageStart ge '2023-07-01' and properties/usageEnd le '2023-07-02'&$top=1000&api-version=2019-10-01

Response:

Azure成本管理API不遵循所需的日期过滤器。

QUERY 2:

GET https://management.azure.com/subscriptions/<subID>/providers/Microsoft.Consumption/usageDetails?$filter=properties/usageStart ge '2023-07-01' and properties/usageEnd le '2023-07-04'&$top=1000&api-version=2019-10-01

Response:

Azure成本管理API不遵循所需的日期过滤器。

Reference:

Manage Azure costs with automation - Microsoft Cost Management

英文:

> I agree with @Anupam Chand, API response differs based on the type of subscription that you are currently using.
>
> To retrieve the usage cost of a subscription within specific duration,
> you need to include $filter in query that works with only Enterprise Agreement (EA) or a pay-as-you-go subscriptions and not supported by
> Microsoft Customer Agreements subscription.

If you have Enterprise Agreement (EA) or a pay-as-you-go subscription, you can make use of below query by including $filter to retrieve the usage cost of a subscription within specific duration:

GET https://management.azure.com/subscriptions/<subID>/providers/Microsoft.Consumption/usageDetails?$filter=properties/usageStart ge '2023-06-01' and properties/usageEnd le '2023-06-02'&$top=1000&api-version=2019-10-01

I have one Azure account with pay-as-you-go subscription like below:

Azure成本管理API不遵循所需的日期过滤器。

When I ran below query by including $filter with different dates, I got different results successfully like this:

QUERY 1:

GET https://management.azure.com/subscriptions/<subID>/providers/Microsoft.Consumption/usageDetails?$filter=properties/usageStart ge '2023-07-01' and properties/usageEnd le '2023-07-02'&$top=1000&api-version=2019-10-01

Response:

Azure成本管理API不遵循所需的日期过滤器。

QUERY 2:

GET https://management.azure.com/subscriptions/<subID>/providers/Microsoft.Consumption/usageDetails?$filter=properties/usageStart ge '2023-07-01' and properties/usageEnd le '2023-07-04'&$top=1000&api-version=2019-10-01

Response:

Azure成本管理API不遵循所需的日期过滤器。

Reference:

Manage Azure costs with automation - Microsoft Cost Management

huangapple
  • 本文由 发表于 2023年7月5日 00:54:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76614605.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定