Home > Software design >  azure amortized cost usagestart and usageend date error while passing it as variable
azure amortized cost usagestart and usageend date error while passing it as variable

Time:07-25

I am trying to pull azure amortized cost at subscription level but when I pass usage_start_date and usage_end_date in hardcoded way I am able to pull data : Example : "https://management.azure.com/subscriptions/" subs "/providers/Microsoft.Consumption/usageDetail?$filter=properties/usageStart eq '2022-05-01' and properties/usageEnd eq '2022-05-31'&metric=AmortizedCost&api-version=2021-10-01"

But when I am passing start usage and start end date as variable it is throwing error. API example:

f"https://management.azure.com/subscriptions/{subs}/providers/Microsoft.Consumption/usageDetails?$filter=properties/usageStart eq {start_date} and properties/usageEnd eq {end_date}&metric=AmortizedCost&api-version=2021-10-01"

like :

'message': 'Billing Period is not supported in (2019-10-01) API Version for Subscription Scope With Web Direct Offer. Please provide the UsageStart and UsageEnd dates in the $filter key as parameters.'}}

{'error': {'code': '400',
  'message': 'Billing Period is not supported in (2021-10-01) API Version for Subscription Scope With Web Direct Offer. Please provide the UsageStart and UsageEnd dates in the $filter key as parameters. (Request ID: f2d9517e-e438-42b3-865e-df2d5888da62)'}}

I have tried many option/combination to pull data by passing date range variable it gave me same error. I have tried API from this link as well:

https://docs.microsoft.com/en-us/azure/cost-management-billing/costs/manage-automation#get-usage-details-for-a-scope-during-specific-date-range

Can you please guide me what I am doing wrong. How can I fix this issue?

CodePudding user response:

You need to include the time along with date

properties/usageStart eq '2022-07-01T00:00:00.0000000Z' and properties/usageEnd eq '2022-07-31T23:59:59.0000000Z'

try this

CodePudding user response:

Finally this help me

not working:
costmanagement_client.usage_details.list( scope=f'/subscriptions/{subscription_id}/', filter=f"properties/usageEnd eq {end_date} and properties/usageStart eq {start_date}")

working:
costmanagement_client.usage_details.list( scope=f'/subscriptions/{subscription_id}/', filter=f"properties/usageEnd eq '{end_date}' and properties/usageStart eq '{start_date}'")

just put in quote

  • Related