2
votes

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?

2

2 Answers

2
votes

I resolved this using a dollar slashy string for the $filter header -

def urlRATECARD = 'https://management.azure.com/subscriptions/xxxx-xxxx-xxxx-xxxx/providers/Microsoft.Commerce/RateCard'
def uriRATECARD = new URIBuilder(urlRATECARD)
String Filter = $/OfferDurableId eq 'MS-AZR-0003p' and Locale eq 'en-AU' and Regioninfo eq 'AU' and Currency eq 'AUD'/$

uriRATECARD.addQueryParam 'api-version','2015-06-01-preview'
uriRATECARD.addQueryParam '$filter', Filter

which creates the following -

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

0
votes

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-.