API getList()

Hi. I’m connecting to Mautic via API with OAuth2.



If I use $leadApi->getList() all leads are retrieved. I want to filter them by field alias. For example, only retrieve leads were company=‘Company’.



Is this the function of the parameter $filter? If it is, what is the format for the value?



Thanks!

Hi. I’m connecting to Mautic via API with OAuth2.

If I use $leadApi->getList() all leads are retrieved. I want to filter them by field alias. For example, only retrieve leads were company=‘Company’.

Is this the function of the parameter $filter? If it is, what is the format for the value?

Thanks!

Hi Alvin,

The filter should support Mautic search commands and there happens to be one for company if that is what you are wanting to search by. For example “company:Company”. That can work for “name:”, “email:”, “list:”, and “owner:” as well if you want to search specifically those fields. I’m afraid other custom fields are currently not queryable but please create a feature request so we can see about getting it added!

Thanks,
Alan

Hi.

If I run search command "email:email@domain.com" in Mautic interface I can filter the lead I want. But if I use it with API connection I’m still retrieving all leads

$filter = 'email:email@domain.com';
$leads = $leadApi->getList($filter);
print_r($leads);

Is this the correct format?

Thanks

Hi.

I tested the other parameters and they are working as expected ($start, $limit, $orderBy, $orderByDir). I’m able to limit and order search results.

What I still can’t do is to filter them based on $filter = ‘company:Company’.

Thanks

Hey Alvin,

I apologize. There was a pending PR on the api library that changed the filter parameter (the old api library code used ‘filter’ when Mautic recognized ‘search’). https://github.com/mautic/api-library So we just merged that PR. You may have to change your code a bit as we converted it to use PSR-4 as we are about to submit it to Packagist. Run composer update then use include __DIR__ . '/vendor/autoload.php'; (if your project is not already using Composer).

Thanks!
Alan

Is working now… Thanks!