'Azure consumption api returning blank value

I am trying to use the azure consumption api to get usage details for my subscription, but it keeps returning a blank array. I know there should be something there.

$VaultName = 
$KeyName = 

$tenantId = 
$applicationId = 
$SubscriptionId =

$apiEndpointUri = "https://management.azure.com/"  
$secret = Get-AzKeyVaultSecret -VaultName $VaultName -Name $KeyName -AsPlainText

$RequestAccessTokenUri = "https://login.microsoftonline.com/$tenantId/oauth2/token"
$body = "grant_type=client_credentials&client_id=$($applicationId)&client_secret=$($secret)&resource=$($apiEndpointUri)" 

$AccessToken = Invoke-RestMethod -Method Post -Uri $RequestAccessTokenUri -Body $body -ContentType $contentType

$apiuri = "https://management.azure.com/subscriptions/$($SubscriptionId)/providers/Microsoft.Consumption/usageDetails?$filter={reportedstartTime=2022-03-01&reportedendTime=2022-04-01}&api-version=2021-10-01"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $($AccessToken.access_token)")

Invoke-RestMethod -Uri $apiuri -Headers $headers | ConvertTo-Json

This is the response every time

{
    "value":  [

              ]
}

I have tried everything I can think of to change the $apiuri around. And I know all the auth parts are correct.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source