# REST API compound filter

**URL:** <https://community.icinga.com/t/rest-api-compound-filter/14230>\
**Category:** Icinga 2\
**Tags:** api\
**Created:** [October 24, 2024, 10:01am UTC](https://community.icinga.com/t/rest-api-compound-filter/14230 "2024-10-24T10:01:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamudo](https://community.icinga.com/letter_avatar_proxy/v4/letter/t/51bf81/32.png) [@tamudo](https://community.icinga.com/u/tamudo)\
**Post date:** [October 24, 2024, 10:01am UTC](https://community.icinga.com/t/rest-api-compound-filter/14230/1 "2024-10-24T10:01:53Z")

</div>

I have been trying to get a list of unacknowleged critical status hosts with curl but for the life of me I can only get one or the other (critical hosts or unackloweged hosts not in critical) . I’ve tried multiple variations of the URL below.

_curl -k -s -S -i -u user:pass ‘[https://server:5665/v1/objects/hosts?filter=host.state==1&+host.acknowledgement==0&attrs=name&attrs=state&attrs=last\_check\_result&pretty=1](https://server:5665/v1/objects/hosts?filter=host.state==1&+host.acknowledgement==0&attrs=name&attrs=state&attrs=last_check_result&pretty=1)’_

I’d prefer not to have to build the query as JSON but I couldn’t find a working example of how to chain the filter like you can do in the web interface.  
Can you do that this type of query with plain curl GET?

---

<div class="post-metadata">

**Author:** ![rivad](https://community.icinga.com/user_avatar/community.icinga.com/rivad/32/5852_2.png) [@rivad](https://community.icinga.com/u/rivad)\
**Post date:** [October 25, 2024, 7:06am UTC](https://community.icinga.com/t/rest-api-compound-filter/14230/2 "2024-10-25T07:06:02Z")

</div>

Did you try to build the query in the web interface and use the resulting URL as a base for your curl call?

---

<div class="post-metadata">

**Author:** ![tamudo](https://community.icinga.com/letter_avatar_proxy/v4/letter/t/51bf81/32.png) [@tamudo](https://community.icinga.com/u/tamudo)\
**Post date:** [October 25, 2024, 7:27am UTC](https://community.icinga.com/t/rest-api-compound-filter/14230/3 "2024-10-25T07:27:31Z")

</div>

I did, the URL is:  
_icingaweb2/monitoring/list/hosts?host\_state=1&host\_acknowledged=0&modifyFilter=1_

Which is what I tried somehow to recreate using REST API but as I said cannot get the two conditions in the filter to apply at the same time

---

<div class="post-metadata">

**Author:** ![moreamazingnick](https://community.icinga.com/user_avatar/community.icinga.com/moreamazingnick/32/7725_2.png) [@moreamazingnick](https://community.icinga.com/u/moreamazingnick)\
**Post date:** [October 25, 2024, 8:05am UTC](https://community.icinga.com/t/rest-api-compound-filter/14230/4 "2024-10-25T08:05:29Z")

</div>

here you go…

```sh
curl -k -s -S -i -u 'root:pass' -H 'Accept: application/json' \
 -H 'X-HTTP-Method-Override: GET' -X POST \
 'https://localhost:5665/v1/objects/hosts' \
 -d '{ "filter": "host.state==1 && host.acknowledgement==0"}'

```

---

<div class="post-metadata">

**Author:** ![rivad](https://community.icinga.com/user_avatar/community.icinga.com/rivad/32/5852_2.png) [@rivad](https://community.icinga.com/u/rivad)\
**Post date:** [October 25, 2024, 8:23am UTC](https://community.icinga.com/t/rest-api-compound-filter/14230/5 "2024-10-25T08:23:31Z")

</div>

Does it work with URL encoding the ampersands?

But for readability I would prefer the JSON filter that @moreamazingnick posted.

---

<div class="post-metadata">

**Author:** ![tamudo](https://community.icinga.com/letter_avatar_proxy/v4/letter/t/51bf81/32.png) [@tamudo](https://community.icinga.com/u/tamudo)\
**Post date:** [October 25, 2024, 8:45am UTC](https://community.icinga.com/t/rest-api-compound-filter/14230/6 "2024-10-25T08:45:05Z")

</div>

Thanks @moreamazingnick this seems to work and I already employed way too much time trying a “plain” cURL request with different approaches so I’ll go with yours and move forward.
