Mautic get user id by email

I had trouble finding information on how to retrieve a contact id by email address from API.

Here is the code I am using:

require __DIR__ . '/vendor/autoload.php';

use Curl\Curl;

$curl = new Curl();

$un = 'your_username';
$pw = 'your_password';
$hash = base64_encode($un.':'.$pw);

$curl->setUserAgent('MyUserAgent/0.0.1 (+');
$curl->setHeader('Content-Type', 'application/x-www-form-urlencoded');
$curl->setHeader('Authorization','Basic '.$hash);

		'search' => '',
		'start'=> 0,
		'limit'=> 1,
		'orderBy'=> 'email',
		'minimal' => false

// convert object to array
$array = json_decode(json_encode($curl->response), true);

// get ID contact

I hope it will help other user.

1 Like

What is the response whey you execute the script

You get the user ID corresponding to the email address passed as a parameter to the API of your Mautic installation.


1 Like