H.Scheidl
H.Scheidl

Reputation: 855

How to filter Azure Resource Management REST call on tags

I would like to get a list of resources in Azure containing a given tag. The basic request form is as follows: https://management.azure.com/subscriptions/{subscriptionId}/resources

I can append $filter parameter, however using tags generates an error, which is likely due to tags being a dictionary.

{"error":{"code":"InvalidFilterInQueryString","message":"Invalid $filter 'tags eq '{}'' specified in the query string."}}

Documentation for filter syntax does not mention how to filter on lists.

Upvotes: 0

Views: 3691

Answers (1)

Nancy Xiong
Nancy Xiong

Reputation: 28284

If you have a tag pair name:value=abc:123, you can append $filter=tagname eq 'abc' and tagvalue eq '123' parameter.

I test this from this Resources - List just via clicking Try it. Add the $filter parameter with values including single quotes.

enter image description here

The response with filtered resources. enter image description here

The full example will be like this:

https://management.azure.com/subscriptions/{subscription-id}/resources?$filter=name eq 'some_name'&api-version={api-version}

You can get more details from this Azure REST API - query parameters for getting all the virtual machine.

Upvotes: 2

Related Questions