Search.../

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:

  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 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

Copy Code
1// NOTE: This example uses the new wix-crm.contacts.appendOrCreateContact()
2// function, which replaces wix-crm.createContact().
3// See the function description for more information, and
4// line 43 for the deprecated example.
5
6import { contacts } from 'wix-crm';
7
8// ...
9
10const contactInfo = {
11 name: {
12 first: 'Ari',
13 last: 'Thereyet'
14 },
15 emails: [
16 {
17 email: 'ari.thereyet@example.com',
18 },
19 {
20 email: 'ari.thereyet.appended.email@example.com'
21 }
22 ],
23 phones: [
24 {
25 tag: 'MOBILE',
26 countryCode: 'US',
27 phone: '601-081-124',
28 primary: true
29 }
30 ]
31};
32
33contacts.appendOrCreateContact(contactInfo)
34 .then((resolvedContact) => {
35 return resolvedContact;
36 })
37 .catch((error) => {
38 console.error(error);
39 });
40
41
42
43// NOTE: This example uses the deprecated
44// wix-crm.createContact() function.
45
46import wixCrm from 'wix-crm';
47
48// ...
49
50let firstName = // get first name
51let lastName = // get last name
52let email = // get email address
53let phone = // get phone number
54
55wixCrm.createContact( {
56 "firstName": firstName,
57 "lastName": lastName,
58 "emails": [email],
59 "phones": [phone]
60} )
61.then( (contactId) => {
62 // contact created
63} );
Create a new contact with custom fields

Copy Code
1// NOTE: This example uses the new wix-crm.contacts.appendOrCreateContact()
2// function, which replaces wix-crm.createContact().
3// See the function description for more information, and
4// line 47 for the deprecated example.
5
6import { contacts } from 'wix-crm';
7
8// ...
9
10const contactInfo = {
11 name: {
12 first: 'Ari',
13 last: 'Thereyet'
14 },
15 emails: [
16 {
17 email: 'ari.thereyet@example.com',
18 },
19 {
20 email: 'ari.thereyet.appended.email@example.com'
21 }
22 ],
23 phones: [
24 {
25 tag: 'MOBILE',
26 countryCode: 'US',
27 phone: '601-081-124',
28 primary: true
29 }
30 ],
31 extendedFields: {
32 'custom.event-we-met-at': 'Tailgate Con',
33 'custom.last-contacted': '2021-04-25'
34 }
35};
36
37contacts.appendOrCreateContact(contactInfo)
38 .then((resolvedContact) => {
39 return resolvedContact;
40 })
41 .catch((error) => {
42 console.error(error);
43 });
44
45
46
47// NOTE: This example uses the deprecated
48// wix-crm.createContact() function.
49
50import wixCrm from 'wix-crm';
51
52// ...
53
54let firstName = // get first name
55let lastName = // get last name
56let email = // get email address
57let phone = // get phone number
58
59let contactInfo = {
60 "firstName": firstName,
61 "lastName": lastName,
62 "emails": [email],
63 "phones": [phone],
64 "customField1": "customValue1",
65 "customField2": "customValue2"
66};
67
68wixCrm.createContact(contactInfo)
69.then( (contactId) => {
70 // contact created
71} );
Create a contact and then send a Triggered Email to the new contact

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} );