Mautic Community Forums

Filtering leads in 'list leads' API request

Hi everybody



I’m using API to manage leads through own PHP classes (due to our framework’s architecture ) and I’m trying to filter leads by the ‘search’ parameter in list leads request. NB: I need to filter them by a custom field.



The API manual states that it’s a “String or search command to filter entities by.”



I’ve tried SQL instructions, key:value, key=value and all kinds of quotes’ combinations with these - nothing seems to impress the API: if the ‘search’ parameter isn’t empty, it always returns an empty array and count=0.





Ok, I got the point: it works exactly like the search bar in the frontend (the ‘key:value’ commands work for name, email and some other standard fields).



Now, can I filter by multiple fields?

Say, I have two custom fields client_id and client_status and I need to retrieve records with client_id=x and client_status=y, is there a way to do it?



UPD: Got it also figured out.



The working format seems to be “field_name1:substring1 field_name2:substring2” with a space between the key:value pairs.



Now, the (hopefully) last question:

Is there a way to search for exact field value, not substring?



Thanks in advance :)




Hi everybody

I’m using API to manage leads through own PHP classes (due to our framework’s architecture ) and I’m trying to filter leads by the ‘search’ parameter in list leads request. NB: I need to filter them by a custom field.

The API manual states that it’s a “String or search command to filter entities by.”

I’ve tried SQL instructions, key:value, key=value and all kinds of quotes’ combinations with these - nothing seems to impress the API: if the ‘search’ parameter isn’t empty, it always returns an empty array and count=0.

Ok, I got the point: it works exactly like the search bar in the frontend (the ‘key:value’ commands work for name, email and some other standard fields).

Now, can I filter by multiple fields?
Say, I have two custom fields client_id and client_status and I need to retrieve records with client_id=x and client_status=y, is there a way to do it?

UPD: Got it also figured out.

The working format seems to be “field_name1:substring1 field_name2:substring2” with a space between the key:value pairs.

Now, the (hopefully) last question:
Is there a way to search for exact field value, not substring?

Thanks in advance :slight_smile: