Search code examples
powershellazuregroovyuriuribuilder

Azure Rate Card api query using URIBuilder


I am having difficulty building the URL correctly using URIBuilder in a grrovy script. This is what it the documentation says it should look like -

https://management.azure.com/subscriptions/{subscription-Id}/providers/Microsoft.Commerce/RateCard?api-version={api-version}&$filter=OfferDurableId eq ’{OfferDurableId}’ and Currency eq ’{Currency}’ and Locale eq ’{Locale}’ and RegionInfo eq ’{RegionInfo}’’

My code -

def urlRATECARD = 'https://management.azure.com/subscriptions/xxxx-xxxx-xxxx-xxxx/providers/Microsoft.Commerce/RateCard'

def uriRATECARD = new URIBuilder(urlRATECARD)

uriRATECARD.addQueryParam 'api-version','2015-06-01-preview'
uriRATECARD.addQueryParam '$filter', 'OfferDurableId eq`0003P`and Locale eq `en-AU` and Regioninfo eq `AU` and Currency eq `AUD`'

outputs -

https://management.azure.com/subscriptions/xxxx-xxxx-xxxx-xxxx/providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview&%24filter=OfferDurableId+eq%600003P%60and+Locale+eq+%60en-AU%60+and+Regioninfo+eq+%60AU%60+and+Currency+eq+%60AUD%60

which fails with the following error -

[Message:Invalid query specified. Please specify valid values for OfferDurableId, Currency, Locale and RegionInfo.]

Can anyone offer the correct way to create this?


Solution

  • If your subscription is Pay-As-You-Go, OfferDurableId is MS-AZR-0003p.

    You could check this example, before OFFER NUMBER, it needs add MS-AZR-.