APIs & Integrations

jkjmouseflow
Member

Change e-mail and merge contacts

Hi Hubspot

 

I am having some difficulties figuring out how the accomplish the following through your contact API:

 

Change e-mail (primary) for a contact and merge contact of old and new e-mail.

 

It seems like the vid of the old e-mail become the vid of the new e-mail and a new contact is created with the old e-mail but not synchronized with request which means that my get contect from old e-mail returns a 404.

 

I have also tryid creating a new contact with the new e-mail and then merge the two contacts together - that works but after a few seconds/minutes the primary e-mail is then set to the old contact e-mail.

 

How do i change the e-mail of a contact and make sure that both old e-mail timeline events and new e-mail timeline events etc will be visible for both history and future data for the new e-mail and that the new e-mail is the primary e-mail?

 

All this of cause have the be through your API.

 

kind regards

 

Jesper 

0 Upvotes
5 Replies 5
lscanlan
HubSpot Alumni
HubSpot Alumni

Change e-mail and merge contacts

Hi Jesper,

 

By using a contact's vid to identify the contact record, you can update a contact's primary email address. Your request URL for a single contact to the Contacts API would look something like this: https://api.hubapi.com/contacts/v1/contact/vid/:vid/profile?hapikey=XXXX, and the request body would look something like:

 

{
  "properties": [
    {
      "property": "email",
      "value": "new-email@hubspot.com"
    }
  ]
}

 

This will update a contact record's email address. Or if you're using the batch create/update endpoint (documented here: https://developers.hubspot.com/docs/methods/contacts/batch_create_or_update), you can also identify by vid or email address.

 

We also have documentation here: https://developers.hubspot.com/docs/methods/contacts/merge-contacts for merging contact records. This is also done by contact record vids. You could retrieve those by getting vids from the endpoint documented here: https://developers.hubspot.com/docs/methods/contacts/get_contacts.

 

If you're still having trouble, could you send along some example contacts / requests that you're making? If I understand what your goal is, I feel like there's no need to actually be creating a new contact record. You're only trying to update the contact record's primary email address, right?

Leland Scanlan

HubSpot Developer Support
0 Upvotes
jkjmouseflow
Member

Change e-mail and merge contacts

What you suggest is what we have always done but it is insufficient.

 

1. it creates a new contact with new vid for the old e-mail.

2. it changes the old contact to have the new e-mail.

 

This is actually ok though i would have expected it to automatically merge new contact with old e-mail into the old contact with the new primary e-mail.

 

To solve this i try to merge but it seems like your API is not sequential meaning it get response on the update e-mail call before the new contact with the old e-mail has been created. This makes my code need queing and delay processing which cant be what you aim for.

 

To test other ways i try first manually to createOrUpdate a contact with the new e-mail and then merge it with the old e-mail contact (tryid with both combination contacts being the vidToMerge and vid in url which yield same end result) which does merge but this again seems to be not sequential as after I get response i can see in the e-mail history that the e-mail has been changed again back to the old e-mail.

If I here need to manually updated the contact with the new e-mail then I again need my code to be queuel and delay processing which I again doubt you aim for.

 

Do you have unawaited async task or processing after respons or somekind of schedule queue batch jobs running which does something when e-mail is changed or contacts are merged?

 

0 Upvotes
jkjmouseflow
Member

Change e-mail and merge contacts

Can I please get an update on this post from a HubSpot developer.

0 Upvotes
lscanlan
HubSpot Alumni
HubSpot Alumni

Change e-mail and merge contacts

Hi @jkjmouseflow,

 

Could you send me some example contacts with this behavior? Specifically I'm looking for an example contact whose primary email was changed. And then also the new contact record that was created with the old email address.

 

Maybe I'm not testing things correctly, but I haven't been able to reproduce this. Even through the batch update/create endpoint, the primary email address is being updated on the (only) contact record. There's no new contact record with an old email address. And when I search by email address (https://developers.hubspot.com/docs/methods/contacts/get_contact_by_email) I get a 404 response. Maybe I'm not sending enough contacts through in my request at the same time. And maybe what you're seeing has something to do with the asynchronous nature of the batch endpoints. But I'll need to see some example records on your end where this is happening.

Leland Scanlan

HubSpot Developer Support
0 Upvotes
jkjmouseflow
Member

Change e-mail and merge contacts

Hi Iscanlan

 

I still have not found a solution for update e-mail and afterwards merge the new and old contact and i dont think its possible withour awaiting async your API has created the new contact with the old e-mail.

 

But i have figured out the reason why the e-mail was reverted after i have created a new contact with the new e-mail and merged it with the old followed by updating the e-mail.

It was due to we was creating a timeline event for the old e-mail afterwards and that that request apperently then sets the old e-mail to the primary e-mail. So you primary e-mail = last seen e-mail? 🙂

 

I can not spent more time on this so lets just end it here.

0 Upvotes