appendOrCreateContact( )
Appends an existing contact or creates a contact if it doesn't exist.
Description
The appendOrCreateContact()
function returns a Promise
that resolves to a contact ID and identity type when a contact is found or created.
When called, appendOrCreateContact()
accepts an object with contact information and follows the steps below.
When one of the conditions is met, this process ends and the specified
data is handled:
- If the current visitor is a logged-in member:
appendOrCreateContact()
reconciles with the member's associated contact. - If the visitor is not a logged-in member:
appendOrCreateContact()
tries to reconcile any specified email addresses and/or phone numbers with an existing contact. - If no contact can be reconciled in the previous steps:
appendOrCreateContact()
tries to reconcile the visitor's session identity with an existing contact. - If no contact can be reconciled and an email address, phone number, or name are provided: A new contact is created and
appendOrCreateContact()
reconciles with the new contact. - If no contact can be created: The Promise is rejected.
appendOrCreateContact()
does not require member authentication,
so it does not return the entire contact object.
The contact's data can be retrieved with
getContact()
from wix-crm-backend
.
How the Data Is Handled
If an existing contact is found:
- The current visitor's session identity is associated with the contact.
- If a specified property is empty in the existing contact, the property is updated with the specified information.
- For arrays, any specified information is added as new array items. This includes
emails
,addresses
,phones
, andlabelKeys
. - No existing data is overwritten or deleted.
Note: If the reconciled contact belongs to a member who isn't currently logged in to the site,
identityType
is returned as"NOT_AUTHENTICATED_MEMBER"
. In that case, no contact properties are modified.
If a new contact is created:
- The new contact's data is populated with the specified contact object.
- The current visitor's session identity is associated with the contact.
Syntax
function appendOrCreateContact(contactInfo: ContactInfo): Promise<ContactIdentification>
appendOrCreateContact Parameters
NAME
TYPE
DESCRIPTION
Contact's information. To reconcile with an existing contact, a phone or email must be provided, or the current session identity must be attached to a contact or member.
If no existing contact can be found, a new contact is created with the specified information.
Returns
Return Type:
NAME
TYPE
DESCRIPTION
ID of the contact that was found or created.
Identity type of the returned contact.
One of:
"CONTACT"
: The returned contact ID belongs to a new or existing contact."MEMBER"
: The returned contact ID belongs to the currently logged-in site member."NOT_AUTHENTICATED_MEMBER"
: The returned contact ID belongs to a site member who is not currently logged in.
Was this helpful?
1import { contacts } from 'wix-crm-frontend';23// ...45const contactInfo = {6 name: {7 first: "Ari",8 last: "Thereyet"9 }10};1112contacts.appendOrCreateContact(contactInfo)13 .then((resolvedContact) => {14 return resolvedContact;15 })16 .catch((error) => {17 console.error(error);18 });
1import { contacts } from 'wix-crm-frontend';23// ...45const contactInfo = {6 name: {7 first: "Ari",8 last: "Thereyet"9 },10 emails: [11 {12 email: "ari.thereyet@example.com",13 },14 {15 email: "ari.thereyet.appended.email@example.com"16 }17 ],18 phones: [19 {20 tag: "MOBILE",21 countryCode: "US",22 phone: "601-081-124",23 primary: true24 }25 ]26};2728contacts.appendOrCreateContact(contactInfo)29 .then((resolvedContact) => {30 return resolvedContact;31 })32 .catch((error) => {33 console.error(error);34 });