# API request filter host.groups

**URL:** <https://community.icinga.com/t/api-request-filter-host-groups/4010>\
**Category:** Icinga 2\
**Tags:** api\
**Created:** [April 7, 2020, 7:25am UTC](https://community.icinga.com/t/api-request-filter-host-groups/4010 "2020-04-07T07:25:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![t3tr1s](https://community.icinga.com/letter_avatar_proxy/v4/letter/t/c37758/32.png) [@t3tr1s](https://community.icinga.com/u/t3tr1s)\
**Post date:** [April 7, 2020, 7:25am UTC](https://community.icinga.com/t/api-request-filter-host-groups/4010/1 "2020-04-07T07:25:45Z")

</div>

Dears,

Task: to query for hosts with have same pattern in hostgroups.  
Tried several approaches that does not work.

Anybody faced such issue?

Thanks,  
/A

```
curl -k -s -u collector:pass -H 'Accept: application/json' -H 'X-HTTP-Method-Override: GET' -X POST \
'https://host:5665/v1/objects/hosts' -d '{ "attrs": ["__name", "address", "vars", "notes"], "filter": "\"ALL-PRODUCTION\" in host.groups", "pretty": true }'
[works]

curl -k -s -u collector:pass -H 'Accept: application/json' -H 'X-HTTP-Method-Override: GET' -X POST \
'https://host:5665/v1/objects/hosts' -d '{ "attrs": ["__name", "address", "vars", "notes"], "filter": "\"*PRODUCTION\" in host.groups", "pretty": true }'
{
"results": []
}

curl -k -s -u collector:pass -H 'Accept: application/json' -H 'X-HTTP-Method-Override: GET' -X POST \
'https://host:5665/v1/objects/hosts' -d '{ "attrs": ["__name", "address", "vars", "notes"], "filter": "match(\"*PRODUCTION*\",host.groups)", "pretty": true }'
{
"results": []
}

curl -k -s -u collector:pass -H 'Accept: application/json' -H 'X-HTTP-Method-Override: GET' -X POST \
'https://host:5665/v1/objects/hosts' -d '{ "attrs": ["__name", "address", "vars", "notes"], "filter": "host.groups==*PRODUCTION*", "pretty": true }'
{
"error": 404.0,
"status": "No objects found."
}

curl -k -s -u collector:pass -H 'Accept: application/json' -H 'X-HTTP-Method-Override: GET' -X POST \
'https://host:5665/v1/objects/hosts' -d '{ "attrs": ["__name", "address", "vars", "notes"], "filter": "host.groups==\"*PRODUCTION*\"", "pretty": true }'
{
"results": []
}

```

Environment:

```
$ icinga2 -V
icinga2 - The Icinga 2 network monitoring daemon (version: 2.11.3-1)
System information:
Platform: Red Hat Enterprise Linux Server
Platform version: 7.8 (Maipo)
Kernel: Linux
Kernel version: 3.10.0-1062.18.1.el7.x86_64
Architecture: x86_64
```

---

<div class="post-metadata">

**Author:** ![anon66228339](https://community.icinga.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@anon66228339](https://community.icinga.com/u/anon66228339)\
**Post date:** [April 14, 2020, 9:59am UTC](https://community.icinga.com/t/api-request-filter-host-groups/4010/2 "2020-04-14T09:59:08Z")

</div>

Hello,

i assume your host\_groups is an array. Then the only filter that will work is like `"\"linux-servers\" in host.groups" }'`, No regex or wildcard is allowed/useable here.  
If you want to do a regex or match you have to create a (string) variable like `vars.string_host_groups = groups.to_string()`.

Regards,  
Carsten
