I’m using Azure Forecast Cost Management API to try to retrieve the forecast cost shown in the azure portal like below.
This is the API I’m using -> https://learn.microsoft.com/en-us/rest/api/cost-management/forecast/usage?tabs=HTTP
This is my request body looks like
{
"Dataset": {
"Aggregation": {
"TotalCost": {
"Function": "Sum",
"Name": "Cost"
}
},
"Granularity": "Monthly"
},
"TimePeriod": {
"From": "2023-02-01",
"To": "2023-02-28"
},
"Timeframe": "Custom",
"Type": "Usage"
}
Everything is working if i did the request not in the 1st day of month. But when i make a request to API in 1st day of month, the request is success and the API give me a response, but i can’t find any information related to forecast cost amount.
I can see the forecast cost from the Azure portal, so i believe there must be a way to retrieve the data. Help me please?
Thanks.
I have try to modify the timeframe, granularity, and others in the request body. But still can’t get the data.
2
Answers
Check the datetime you are using is the same as what is being used on Azure for the service/plan/account or whatever, these can differ on both sides.It could also be that Azure requires the datetime in GMT or a US format.
So it may be that your request is being read as last month, but azure is only providing data for this in the upcoming month.
To test this try switching to prior dates and see if any dates in the past give you the same data as what you are getting on the 1st. If so I would say that is what is happening.
The fact it only occurs on the first but the data is available in the portal would indicate to me it is definitely something to do with the timezone, but I could be wrong.
Personally I use Azure Cost Management connector in Power BI Desktop to retrieve the data. I scheduled a daily refresh and I never had problems.
I know for sure that there are problems with calculation in the early days of the month and I have a colleague that withdraw the last month after the first week.
I suggest you to open a ticket with the Azure Billing support.