# API Rest - Advanced filtering with OR expression

**URL:** <https://forum.mautic.org/t/api-rest-advanced-filtering-with-or-expression/27576>\
**Category:** Development\
**Tags:** development\
**Created:** [March 31, 2023, 2:21pm UTC](https://forum.mautic.org/t/api-rest-advanced-filtering-with-or-expression/27576 "2023-03-31T14:21:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aadam](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@aadam](https://forum.mautic.org/u/aadam)\
**Post date:** [March 31, 2023, 2:21pm UTC](https://forum.mautic.org/t/api-rest-advanced-filtering-with-or-expression/27576/1 "2023-03-31T14:21:25Z")

</div>

Hello,

I would like to retrieve form submissions depending on two fields, using an OR expression.

First, I can filter on one field value with the following request:

```auto
{{base_uri}}/api/forms/{{form_id}}/submissions?where[0][col]=r.field&where[0][expr]=like&where[0][val]=%value%

```

This works well. Now I want to search on an other field value if the first one does not match (OR expression). I cannot find how to do this.

I tried this:

`{{base_uri}}/api/forms/{{form_id}}/submissions?where[0][col]=r.field&where[0][expr]=like&where[0][val]=%value%&where[1][col]=r.field2&where[1][expr]=like&where[1][val]=%value2%`

But it obviously does not work because it uses an AND operator I guess.

And this:

`{{base_uri}}/api/forms/{{form_id}}/submissions?where[0][col]=r.field&where[0][expr]=like&where[0][val]=%value%&orWhere[0][col]=r.field2&orWhere[0][expr]=like&orWhere[0][val]=%value2%`

But it seems that my query parameter orWhere is not taken into account.

Do you know how can I achieve this ?

Thank you for your time.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [May 3, 2023, 10:05am UTC](https://forum.mautic.org/t/api-rest-advanced-filtering-with-or-expression/27576/2 "2023-05-03T10:05:25Z")

</div>

I haven’t tested it, but it seems that the API Library has an “orX” option:

> <https://github.com/mautic/api-library/blob/5407d715b3b622a577ff96f51b54e1e610a29844/lib/QueryBuilder/WhereBuilder.php#L262>

It’s an alias for the Doctrine’s orX method:

> **[The QueryBuilder - Doctrine Object Relational Mapper (ORM)](https://www.doctrine-project.org/projects/doctrine-orm/en/2.14/reference/query-builder.html#line-number-5775ab09aefa638b14c776a733b4b61d2e324b74-54)**
>
> Doctrine Object Relational Mapper Documentation: The QueryBuilder

Let us know if it works, please.

---

<div class="post-metadata">

**Author:** ![aadam](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@aadam](https://forum.mautic.org/u/aadam)\
**Post date:** [July 20, 2023, 8:13am UTC](https://forum.mautic.org/t/api-rest-advanced-filtering-with-or-expression/27576/3 "2023-07-20T08:13:14Z")

</div>

I do not use the API Library but simply use cURL. However, I installed and tested it to determine how the query parameters were set when using the orX method. This allowed me to obtain this result which works:

> {{base\_uri}}/api/forms/{{form\_id}}/submissions?where[0][expr]=orX&where[0][val][0][col]=r.field&where[0][val][0][expr]=like&where[0][val][0][val]=%value1%&where[0][val][1][col]=r.field&where[0][val][1][expr]=like&where[0][val][1][val]=%value2%

Thank you for helping @escopecz

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)\
**Post date:** [July 21, 2023, 8:13pm UTC](https://forum.mautic.org/t/api-rest-advanced-filtering-with-or-expression/27576/4 "2023-07-21T20:13:34Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
