Triggered when one or more source contacts are merged into a target contact.
function wixCrm_onContactMerged(event: ContactMergedEvent): void;
Information about the source and target contacts, and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixCrm_onContactMerged(event) {
const eventId = event.metadata.id;
const sourceContactIds = event.data.sourceContactIds;
const firstSourceContactId = event.data.sourceContactIds[0];
const targetContactId = event.data.targetContact._id;
const targetContactName = `${event.data.targetContact.info.name.first} ${event.data.targetContact.info.name.last}`;
console.log("Target contact updated by merge", targetContactId);
console.log("Source contacts deleted by merge", sourceContactIds);
}
/* Full event object:
* {
* "metadata": {
* "id": "c6f09a37-8c03-469e-bfa8-9a40939cac66",
* "entityId": "87227cf7-4ed5-47c3-8261-795d16b6dc9f",
* "eventTime": "2024-01-14T10:26:38.848Z",
* "triggeredByAnonymizeRequest": false
* },
* "data": {
* "sourceContactIds": [
* "2ca312b3-e850-465a-9991-c59c9c140919"
* ],
* "targetContactId": "527676cc-2f20-4318-a76f-07854e02be2c",
* "targetContact": {
* "revision": 3,
* "source": {
* "sourceType": "ADMIN"
* },
* "lastActivity": {
* "activityDate": "2024-01-14T10:26:38.848Z",
* "activityType": "CONTACT_MERGED"
* },
* "primaryInfo": {
* "email": "j.jackson@example.com",
* "phone": "646-458-4589"
* },
* "info": {
* "name": {
* "first": "Jeremy",
* "last": "Jackson"
* },
* "emails": {
* "items": [
* {
* "tag": "UNTAGGED",
* "email": "j.jackson@example.com",
* "primary": true,
* "_id": "dec280b7-a8dd-45bc-a7de-0da9166caf63"
* }
* ]
* },
* "phones": {
* "items": [
* {
* "tag": "MOBILE",
* "countryCode": "US",
* "phone": "646-458-4589",
* "e164Phone": "+16464584589",
* "primary": true,
* "_id": "c40ef68a-2cc9-4ab0-adb4-97be64c57878"
* },
* {
* "tag": "MOBILE",
* "countryCode": "IL",
* "phone": "55-334-3434",
* "e164Phone": "+972553343434",
* "primary": false,
* "_id": "caa48199-d40d-4c2e-9eec-ae9bdf8e4f35"
* }
* ]
* },
* "addresses": {
* "items": [
* {
* "tag": "HOME",
* "address": {
* "formatted": "Israel",
* "country":"IL"
* },
* "_id": "6a2fd038-fa7a-486d-9230-e48bcea824bc"
* }
* ]
* },
* "labelKeys": {
* "items": [
* "custom.anonymous"
* ]
* },
* "extendedFields": {
* "items": {
* "contacts.displayByLastName": "Jackson Jeremy",
* "emailSubscriptions.effectiveEmail": "j.jackson@example.com",
* "custom.age": 37,
* "contacts.displayByFirstName": "Jeremy Jackson"
* }
* }
* },
* "_id": "527676cc-2f20-4318-a76f-07854e02be2c",
* "_createdDate": "2024-01-14T10:22:43.952Z",
* "_updatedDate": "2024-01-14T10:26:38.848Z"
* }
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.