1

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://learn.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?

kakaji
  • 161
  • 9
  • Can you try surrounding your start/end dates with ticks (e.g., `properties/usageStart eq '{start_date}' and...`)? I suspect there's an error internally since those are missing and that it's trying to fall back to billing period. – Michael Flanakin Jul 25 '22 at 22:14

2 Answers2

1

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

kakaji
  • 161
  • 9
0

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

  • No man i tried {'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. } – kakaji Jul 25 '22 at 08:53
  • any other ideas – kakaji Jul 25 '22 at 08:53