JSON - Filter with OR

Hi,

I am setting up api integration and need to pull a record(s) based on a telephone number being equal to phone_work or phone_mobile data.

Filtering based on one of the 2 is fine (phone_work below):

https://crm.xxx.com/Api/V8/module/Contacts?filter{{phone_work}}{{eq}}=[Number]

but I can’t get the syntax right to query both fields. The documentation only gives an example of AND being used and that doesn’t show 2 fields being validated.

Any ideas?

Thanks,

James

Hey,

To filter on multiple fields, I think your request would possibly need a

&filter[FIELD_NAME][eq]=[VALUE]

parameter for each field?

With the

&filter[operator]=and

Separating them.

(Unless another user is aware of an easier/cleaner way?)

Something similar to this, perhaps?:

crm.xxx.com/Api/V8/module/Contacts?filter[phone_work][eq]=1234&filter[operator]=and&filter[phone_mobile][eq]=1234


That should return items where both "phone_work" and "phone_mobile" are "1234", sent as a GET request to the CRM through the V8 Api

Is that similar to what you’re looking for?

1 Like

I tried with :

https://crm.xxx.com/Api/V8/module/Contacts?filter[phone_work][eq]=12345&filter[operator]=OR&filter[phone_home][eq]=12345&filter[phone_mobile][eq]=12345&filter[phone_other][eq]=12345

And it pulls up multiple records where the values don’t match.

This outcome is the same with this verion:

https://crm.xxx.com/Api/V8/module/Contacts?fields[Contacts]=id,first_name,last_name,phone_work,phone_mobile&filter[operator]=OR&filter[phone_home][eq]=12345&filter[phone_mobile][eq]=12345&filter[phone_work][eq]=12345&filter[phone_other][eq]=12345

With AND, it will only pull up a record (correctly) when all phone fields for that record are populated with 12345

Hey,

I’ve been having a look into this

You’re right in that the records don’t match the query posted

It looks like there may be an existing issue with the “OR” parameter in the V8 API:

Reportedly, a parameter gets appended for “OR DELETED = 0”
Which will return essentially all records

However, a user has submitted a fix for this:

The changes made here appear to resolve the issue

I’d given it a quick check with that change made, and results seem to be much more accurate for the “OR” condition


One thing to note though is that this change is currently not upgrade-safe, and may be overwritten by upgrades. (As it has not yet been accepted into the main project)
If you make the changes above, are you able to see more accurate results?

Perfect. Made the change and all working fine. TYVM!

Great, glad to hear it!