Mautic Community Forums

Get contact by other field than ID via API

Is it possible to get a contact via the API with another field than the ID? For example an email address or a custom field like ‘accesscode’?

$contact = $contactApi->get($id);

I only see ID as a option in documentation and other code examples online.

Your software
My Mautic version is: 4
My PHP version is: 7.4
My Database type and version is: latest

Hi, as I understand you should be able to get details about contacts with specific email by using this method here: < api-library/Contacts.php at 9087ddec6400eb0c8aa43859eb7710cc9948c1ce · mautic/api-library · GitHub >, then you use details to get lead id and use lead id from that point on.

Thanks @mzagmajster. How would I use that method via the API? Something like this?


If so, is there a whole list of functions available to use via the API?

Since method actually triggers search as I understand it, I would go with something like:

$search = 'email: ' . $email;
$minimal = true;
$contactAp->getIdentified($search, 0, 0, '', 'ASC', true, $minimal);

The exact values for specific parameters depends on your situation, and I leave the experimenting to you, but the above I think basically captures what you want.