Search.../

mergeContacts( )

Developer Preview

Merges source contacts into a target contact.

Description

Merging contacts has these effects on the target contact:

  • No target contact data is overwritten or deleted.
  • Arrays (emails, phones, addresses, and labels) are merged from the source contacts.
  • If merging more than one source contact, the 1st source is given precedence, then the 2nd, and so on.

Important: Merges cannot be undone. Use Preview Merge Contacts to test before merging.

Source contacts are deleted when merging. However, if a source contact is a site member or contributor, the merge fails because site contributors and members can't be deleted. Site members and contributors can be target contacts only.

After merging, if you call Get Contact with a deleted source contact ID, the target contact ID is returned. This is supported when calling Get Contact only. Deleted source contact IDs are not supported on any other endpoint.

Merging contacts triggers these webhooks:

  • Contact Merged is triggered.
  • Contact Updated is triggered for the target contact. originatedFrom is set to merge.
  • Contact Deleted is triggered for each source contact. originatedFrom is set to merge.

This function is not a universal function and runs only on the backend.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function mergeContacts(targetContactId: string, targetContactRevision: number, options: MergeContactsOptions): Promise<MergeContactsResponse>

mergeContacts Parameters

NAME
TYPE
DESCRIPTION
targetContactId
string

Target contact ID.

targetContactRevision
number

Target contact revision number, which increments by 1 each time the contact is updated. To prevent conflicting changes, the target contact's current revision must be passed.

options
Optional
MergeContactsOptions

Merge contacts options.

Returns

Return Type:

Promise<
MergeContactsResponse
>
NAME
TYPE
DESCRIPTION
contact
Contact

Updated target contact.

Was this helpful?

mergeContacts example

Copy Code
1import { contacts } from 'wix-crm.v2';
2
3 async function mergeContacts(targetContactId, targetContactRevision, options) {
4 try {
5 const result = await contacts.mergeContacts(targetContactId, targetContactRevision, options);
6
7 return result;
8 } catch (error) {
9 console.error(error);
10 // Handle the error
11 }
12 }
13