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.

Update:
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:
https://your.mautic.url/api/contacts?where[0][col]=email&where[0][expr]=equals&where[0][val]=whyisithard@example.com

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.

Regards,

Mike

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