【问题标题】:How to apply filter on results from List all Azure Rest API如何对列出所有 Azure Rest API 的结果应用筛选器
【发布时间】:2021-03-11 19:26:33
【问题描述】:
我想对通过 NSG 返回的所有结果应用过滤器,只针对名称或特定名称,这可能吗?
$uri = "https://management.azure.com/subscriptions/xxxxxx/providers/Microsoft.Network/networkSecurityGroups?`$filter=name eq 'xxx-nsg'&api-version=2020-07-01"
这将返回没有过滤器的所有结果。我想用 equals/contains 来过滤
【问题讨论】:
标签:
azure
rest
azure-rest-api
【解决方案1】:
一种可能的解决方案是使用List Resources API。这允许您指定 $filter 条件并支持 contains 查询。
例如,我尝试列出 Azure 订阅中包含 v2 的存储帐户。这是我的请求 URL 的样子:
https://management.azure.com/subscriptions/xxxx/resources?api-version=2020-06-01&$filter=resourceType eq 'Microsoft.Storage/storageAccounts' and substringof('v2', name)
对你来说,我猜同样的 URL 应该是这样的:
https://management.azure.com/subscriptions/xxxx/resources?api-version=2020-06-01&$filter=resourceType eq 'Microsoft.Network/networkSecurityGroups' and substringof('xxx', name)