appendOrCreateContact( )


Appends an existing contact or creates a contact if it doesn't exist.

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:

  1. If the current visitor is a logged-in member: appendOrCreateContact() reconciles with the member's associated contact.
  2. 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.
  3. If no contact can be reconciled in the previous steps: appendOrCreateContact() tries to reconcile the visitor's session identity with an existing contact.
  4. 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.
  5. 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, and labelKeys.
  • 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.
Method Declaration
Copy
Method Parameters
contactInfoContactInfoRequired

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:Promise<ContactIdentification>
Was this helpful?
Yes
No