How to automate the merging of contacts

I have an API injecting records into mautic. In several instances the record already exists in mautic but has a different email address. I am able to identify them as being duplicates via matching a custom field, in the case csa_no

Is it possible to create a campaign, or some other method, to automatically check for duplicates based on the custom field and then merge the 2 records?

As you already use the API, maybe you could query for matching contacts and merge the data on your side? In my experience Mautic is very limited when you try to do such things within an campaign.

Some pseudo code may look like:

$api = new MauticContactsApi();
$list = $api->getList("csa_no:{$csaNo}", 0, 100, '', 'asc', true, false);

That would give you all contacts that need merging. After that, you could simply update the merged records as you would have the ID then.

1 Like


Not being a coder, could I ask you to break down your code with a few explanations so I can better understand it and adapt it to my needs?

I use n8n to manage the API side of things and they have a function node I could use to get the job done. The hard part for me is the actual function…

Oh jeah, I know this :wink:

Unfortunately I do not have any practical experience with n8n. In lingers in my bucket list for some time now, but as a programmer the more natural way is to code it directly.

Maybe you can try to merge the contacts on the CLI level, but I also did not use that yet.

Look for the command mautic:contacts:deduplicate and for reference here:

I think you may need a helping hand from some IT guy.


I can pull a javascript function into n8n so if you could help me shape up the function, I can figure out how to get n8n to use it.

PS n8n is amazing. They have a dedicated mautic node as well.

Hi Rob, did you check out this one?


1 Like