Search.../

createContact( )

Deprecated. This function will continue to work, but a newer version is avilable 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:

  1. Add the new import statement:

    import { contacts } from 'wix-crm'
    javascript | Copy Code
  2. If you plan to migrate all contact functions that use wixCrm, remove the original import wixCrm statement.

  3. Look for any code that uses wixCrm.createContact(), and replace it with with contacts.appendOrCreateContact(). Update your code to work with the structure of the new appendOrCreateContact() call and response properties.

  4. 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 the contactInfo 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
contactInfo

ContactInfo

The information for the contact being created or updated.

Returns

Fulfilled - The ID of the new or updated contact. Rejected - Error message.

Return Type:

Promise<string>

Was this helpful?

Create a new contact

Code Example

Copy Code
1import wixCrm from 'wix-crm';
2
3// ...
4
5let firstName = // get first name
6let lastName = // get last name
7let email = // get email address
8let phone = // get phone number
9
10wixCrm.createContact( {
11 "firstName": firstName,
12 "lastName": lastName,
13 "emails": [email],
14 "phones": [phone]
15} )
16.then( (contactId) => {
17 // contact created
18} );
Create a new contact with custom fields

Code Example

Copy Code
1import wixCrm from 'wix-crm';
2
3// ...
4
5let firstName = // get first name
6let lastName = // get last name
7let email = // get email address
8let phone = // get phone number
9
10let contactInfo = {
11 "firstName": firstName,
12 "lastName": lastName,
13 "emails": [email],
14 "phones": [phone],
15 "customField1": "customValue1",
16 "customField2": "customValue2"
17};
18
19wixCrm.createContact(contactInfo)
20.then( (contactId) => {
21 // contact created
22} );
Create a contact and then send a Triggered Email to the new contact

Code Example

Copy Code
1import wixCrm from 'wix-crm';
2
3$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").value
16 }
17 } );
18 } );
19 } );
20} );