Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ivymasterman's avatar

How to specify "or" conditions in a JSON API query string?

For now, all of my requests to the backend were in an "AND" relationship.

For example, if I want to get a user with the "firstName" of "Alex", and that is employed in a company "FB", I would write:

http://localhost:80/api/users?filter[firstName]=Alex&filter[company][name]=FB

How would you specify an "or" relationship in the JSON API query? Is there some standard way of doing this? How would a more complex query look like, eq (firstName and company) or (lastName and company)?

0 likes
1 reply
omardev's avatar

You can just add a new field with name filterOperator and it can be either AND or OR for example

Example for AND:

http://localhost:80/api/users?filter[firstName]=Alex&filter[company][name]=FB&filterOperator=AND

Example for OR:

http://localhost:80/api/users?filter[firstName]=Alex&filter[company][name]=FB&filterOperator=OR

for more complex query you could just group them like filter[group1][firstName]=Alex&filter[group1][company]=Facebook&filter[group2][lastName]=Tom&filter[group2][company]=Facebook&filterOperator=OR

1 like

Please or to participate in this conversation.