使用URIBuilder的Azure费率卡api查询



我很难在grrovy脚本中使用URIBuilder正确构建URL。这就是文件所说的它应该是什么样子-

https://management.azure.com/subscriptions/{subscription Id}/providers/Microsoft.Commerce/RateCard?api版本={api版本}&filter=OfferDurableId eq"{OfferDurable Id}"和Currency eq"{Currency}"以及Locale eq"〔Locale}〕"和RegionInfo eq"}RegionInfo}">

我的代码-

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`'

输出-

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

失败,并出现以下错误-

[消息:指定的查询无效。请为OfferDurableId、Currency、Locale和RegionInfo指定有效值。]

有人能提供正确的创建方法吗?

我使用$filter头的美元斜杠字符串-解决了这个问题

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

它创建了以下内容-

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

如果您的订阅是Pay-As-You-Go,那么OfferDurableId就是MS-AZR-0003p

您可以检查这个例子,在OFFER NUMBER之前,它需要添加MS-AZR-

相关内容

  • 没有找到相关文章

最新更新