azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

ODataQuery parametr of Get-AzureRmResource still fails to add $filter properly

Open eosfor opened this issue 9 years ago • 8 comments

Cmdlet(s)

PowerShell Version

PSVersion 5.0.10586.117

Module Version

Get-AzureRmResource : 4.0.0 : AzureRM.Resources

OS Version

10.0.10586.117

Description


$RateCardApiVersion = "2015-06-01-preview"
$Currency = ‘USD’
$Locale = ‘en-US’
$RegionInfo = ‘US’
$OfferDurableId = ‘MS-AZR-0003P’
$subscriptionId = 'some GUID'
$uri = "/subscriptions/{0}/providers/Microsoft.Commerce/RateCard" -f $subscriptionId
$query = "`$filter=OfferDurableId eq '{0}' and Currency eq '{1}' and Locale eq '{2}' and RegionInfo eq '{3}'" -f $OfferDurableId, $Currency, $Locale, $RegionInfo

Get-AzureRmResource -ResourceId $uri -ApiVersion $RateCardApiVersion -ODataQuery $query -Debug -Verbose

This fails with Get-AzureRmResource : {"Message":"Invalid query specified. Please specify a valid filter in format of $filter"}

Debug Output

in the debug output I see the following the request URI seems to be wrong, it misses $filter completely

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/some guid/providers/Microsoft.Commerce/RateCard?OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq
'US'&api-version=2015-06-01-preview

Headers:
User-Agent                    : AzurePowershell/v4.0.0.0,PSVersion/v5.0.10586.117
ParameterSetName              : Get a single resource by its Id.
CommandName                   : Get-AzureRmResource

Body:


DEBUG: ============================ HTTP RESPONSE ============================

Script/Steps for Reproduction

eosfor avatar May 11 '17 12:05 eosfor

I see the same problem, accept I don't get any errors. In my case the $filter= is just removed. However, you can trick it to work. This is what I did: $foo=bar&$filter=. It seems the filter is busted only when it is the first parameter.

leovms avatar May 12 '17 11:05 leovms

@TianoMS Hey Tian, would you mind taking a look at this issue?

cormacpayne avatar May 16 '17 21:05 cormacpayne

Looks like a bug in Get-AzureRmResource. Add @ravbhatnagar to triage.

TianoMS avatar May 18 '17 19:05 TianoMS

@eosfor hit the same issue, after hacking it a bit it seems like an encoding issue, worked around passing filter like this

%24filter=...

troshko111 avatar May 22 '17 23:05 troshko111

@TarasRoshko - awesome workaround, I have spent a couple of hours trying various different workaround before I stumbled across this thread.

clawrenceks avatar Jun 01 '17 14:06 clawrenceks

@Tiano2017 would you mind taking a look at this issue?

cormacpayne avatar Jul 03 '18 22:07 cormacpayne

:bell: Routing this issue to @act-identity-squad.

This scenario targets the retired Microsoft.Commerce/RateCard preview API and the retired Get-AzureRmResource cmdlet, and does not reproduce as filed. If you hit issues with -ODataQuery on current Get-AzResource against a supported API, please open a fresh issue with the exact command and -Debug output.

MaddyMicrosoft avatar Aug 24 '26 09:08 MaddyMicrosoft