Mautic Community Forums

Mautic API - Editing contact by email

Hello all,

While going over Mautic’s REST API documentation to learn how to edit contacts, I had faced a question.
Given that the a contact’s ID field is internal to mautic (it’s set automatically when creating a contact and not related to any other 3rd party ID field), how can one know what is the ID of the contact he would like to edit?

As I expect that the unique property of contacts is the email field, how can I edit a contact via the API using the email as an identifier?
I did a little research and found that if I call the /create/ with an existing email address, it will modify the existing contact with the given email. As this is not very intuitive (and not documented), I was wondering if this is the correct way of doing things.

Sorry if the solution is trivial and I haven’t figured it out, but mostly an internal ID field isn’t being used as an identifier for an external API usage.

Thanks in advance.

So the two ways I found in order to achieve that are:

  1. Calling /contacts/new with an existing email address, which will modify the contact
  2. Calling /contacts with where clause, which has a horrific syntax (see an example below).

Am I missing a different, better, way of editing a contact? This should be so intuitive to do!

Where clause example:

Hi @crispyholiday

Yeah, I was faced with this challenge as well, and simply did a call of the email/id, and then a push back.

Correct if the email is already present, then it will update, but if not known that is the way I went.

Looking forward to someone else helping out here.



Hey @mikew ,
What do you mean by “did a call of the email/id and then a push back?”

@crispyholiday I was just looking at this exact same thing, editing a contact via the API and I was going to get the ID from the cookie, mtc_id, however, it turns out that the /contact/ID/edit functionality doesn’t appear to work at all, at least not as documented.

PATCH requests return 200 response with nothing changed and PUT requests return 200 response and delete all details on the contact!!!

So, the /contact/new with the email address appears to be the best way to go and actually works better for me and my use case as I was looking to see if a contact existed and then edit it if it did or create it if it didn’t (the functionality PUT should provide), so thanks for pointing out that it worked like that.

Just found this has already been reported as a bug on the Github issue tracker: