createContact( )
Deprecated.
This function will continue to work, but a newer version is available at
wix-crm.contacts.appendOrCreateContact()
.
Description
Creates a new contact or updates an existing contact.
Migration Instructions
If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to
wix-crm.contacts.appendOrCreateContact()
.To migrate to the new function:
Add the new import statement:
javascript | Copy Codeimport { contacts } from 'wix-crm'If you plan to migrate all contact functions that use
wixCrm
, remove the originalimport wixCrm
statement.Look for any code that uses
wixCrm.createContact()
, and replace it withcontacts.appendOrCreateContact()
. Update your code to work with the structure of the newappendOrCreateContact()
call and response properties.Test your changes to make sure your code behaves as expected.
The createContact()
function returns a Promise that resolves to the newly
created or updated contact's ID when the contact has been created or updated.
The passed ContactInfo
object must contain at least one
email address or phone number.
Calling createContact()
performs one of the following. (The contact information
specified in the contactInfo
parameter matches an existing contact if it
contains an email address or phone number from an existing contact.)
- If there is no matching existing contact, a new contact is created using the
information specified using the
contactInfo
parameter. - If there is a matching existing contact, it is updated with the information
specified using the
contactInfo
parameter. Any existing contact information that is not explicity overridden in thecontactInfo
parameter retains its existing value.
Note: You cannot use the
createContact()
function to update contact information for existing site members. You can use it to update other site contacts.
Syntax
function createContact(contactInfo: ContactInfo): Promise<string>
createContact Parameters
NAME
TYPE
DESCRIPTION
The information for the contact being created or updated.
Returns
Fulfilled - The ID of the new or updated contact. Rejected - Error message.
Return Type:
Was this helpful?
This example uses a deprecated function.
1import wixCrm from 'wix-crm';23// ...45let firstName = // get first name6let lastName = // get last name7let email = // get email address8let phone = // get phone number910wixCrm.createContact( {11 "firstName": firstName,12 "lastName": lastName,13 "emails": [email],14 "phones": [phone]15} )16.then( (contactId) => {17 // contact created18} );19
This example uses a deprecated function.
1import wixCrm from 'wix-crm';23// ...45let firstName = // get first name6let lastName = // get last name7let email = // get email address8let phone = // get phone number910let contactInfo = {11 "firstName": firstName,12 "lastName": lastName,13 "emails": [email],14 "phones": [phone],15 "customField1": "customValue1",16 "customField2": "customValue2"17};1819wixCrm.createContact(contactInfo)20.then( (contactId) => {21 // contact created22} );23
This example uses a deprecated function.
1import wixCrm from 'wix-crm';23$w.onReady(function () {4 $w("#myButton").onClick( () => {5 wixCrm.createContact( {6 "firstName": $w("#firstName").value,7 "lastName": $w("#lastName").value,8 "emails": [$w("#email").value],9 "phones": [$w("#phone").value]10 } )11 .then( (contactId) => {12 wixCrm.emailContact("thankyou", contactId, {13 "variables": {14 "firstName": $w("#firstName").value,15 "lastName": $w("#lastName").value16 }17 } );18 } );19 } );20} );21