Rest API: Query Filter multiple fields using OR

Hi,
I have been searching for few days and tried different combinations to test the possibility of querying ERPNext for two fields value existance. The scenario I am trying to achieve is when our website gets a new order, I query ERPNext to check if the phone number or email already exist and accordingly create the order with the existing contact details. When I try the below approach, if the customer has changed their mobile or email address the query returns no records since its using AND operator. I tried different combinations of OR and II but kept getting errors. Appreciate your guidance and suggestions, thanks.

https://mydomain/api/resource/Contact?fields=["*"]&filters=[["email_id","=","xyz.abcd@gmail.com"], ["mobile_no","=","12345678"]]

I don’t think OR filters are supported in REST API.

Can you open a github issue (feature request) for this?

Potential solution could be very small change: https://github.com/frappe/frappe/compare/develop...ankush:or_filters_rest

Edit: raised PR: https://github.com/frappe/frappe/pull/15103

2 Likes

Thanks alot, this is something that would make it easier to use the built-in REST API without customization.

@ankush Thanks again. I can see that the change was committed. What would be the syntax for the OR filter?

Syntax will be same as filters. You should pass or_filters as param. @yabdali

1 Like

@ChillarAnand Thanks, do you mean to have the code as per the below example?
https://mydomain/api/resource/Contact?fields=["*"]&or_filters=[["email_id","=","xyz.abcd@gmail.com"], ["mobile_no","=","12345678"]]
If so, I will try it after updating my docker image…

Yeah, seems correct. Though it’s not released yet, it should be part of the next v13 release.