英文:
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:
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:
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:
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:
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:
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:
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:
Reference:
Manage Azure costs with automation - Microsoft Cost Management
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论