Azure - Usage Consumption API - Incomplete Dates

156 views Asked by At

I am trying to get the consumption usage details for a subscription in a given billing period but I am not getting complete results as if I would be getting by using PowerShell:

To get usage details for a given period, API request:

$ConsumtionUsagesUri = "https://management.azure.com/subscriptions/$subId/providers/Microsoft.Billing/billingPeriods/202008/providers/Microsoft.Consumption/usageDetails?`$expand=meterDetails,additionalProperties&api-version=2019-10-01"

The resulting response only returns the first 11 days of usage: Aug 1st to Aug 11th or in another month, 5 days or so.

2020-08-11T00:00:00.0000000Z 2020-08-10T00:00:00.0000000Z 2020-08-09T00:00:00.0000000Z 2020-08-08T00:00:00.0000000Z 2020-08-07T00:00:00.0000000Z 2020-08-06T00:00:00.0000000Z 2020-08-05T00:00:00.0000000Z 2020-08-04T00:00:00.0000000Z 2020-08-03T00:00:00.0000000Z 2020-08-02T00:00:00.0000000Z 2020-08-01T00:00:00.0000000Z

This approach used to be working fine up until a few days ago.

Thanks everyone for the help!

1

There are 1 answers

0
bozx On BEST ANSWER

Update:

I am quite new to REST API and the solution was in the nextLink:

PowerShell:
$array = @()
do{
$ConsumtionUsages = Invoke-RestMethod -Method Get -Uri $ConsumtionUsagesUri -Headers $Headers
$array+=$ConsumtionUsages.value
$ConsumtionUsagesUri = $ConsumtionUsages.nextLink
} until ($ConsumtionUsagesUri -eq $null)