Search.../

createContact( )

Creates a new contact.

Description

The createContact() function returns a Promise that resolves to the new contact when it is created.

Note: This function replaces the deprecated wixCrmBackend.createContact(). The deprecated function will continue to work, but it will not receive updates. To keep any existing code compatible with future changes, see the migration instructions.

The contactInfo parameter object must include a name, phone number, or email address. If all 3 of these parameters are missing, the contact won't be created.

By default, if the call contains an email already in use by another contact, the new contact won't be created. To override this behavior, set allowDuplicates in the options object to true.

Note: Only visitors with Manage Contacts permissions can create contacts. You can override the permissions by setting the suppressAuth option to true.

Syntax

function createContact(contactInfo: ContactInfo, [options: Options]): Promise<Contact>

createContact Parameters

NAME
TYPE
DESCRIPTION
contactInfo
ContactInfo

Contact info.

options
Optional
Options

Contact creation options.

Returns

Fulfilled - Contact.

Return Type:

Promise<Contact>
NAME
TYPE
DESCRIPTION
_id
string

Contact ID.

revision
number

Revision number, which increments by 1 each time the contact is updated. To prevent conflicting changes, the existing revision must be used when updating a contact.

source
Source

Details about the contact's source.

_createdDate
Date

Date and time the contact was created.

_updatedDate
Date

Date and time the contact was last updated.

lastActivity
LastActivity

Details about the contact's last action in the site.

primaryInfo
PrimaryInfo

Contact's primary phone and email.

info
Info

Contact's details.

Was this helpful?

Create a new contact with a name

Copy Code
1import { contacts } from 'wix-crm-backend'
2
3export function myCreateContactFunction() {
4 const contactInfo = {
5 name: {
6 first: "Ari",
7 last: "Thereyet"
8 }
9 };
10
11 const options = {
12 allowDuplicates: false,
13 suppressAuth: false
14 };
15
16 return contacts.createContact(contactInfo, options)
17 .then((contact) => {
18 return contact;
19 })
20 .catch((error) => {
21 console.error(error);
22 });
23}
24
25/* Promise resolves to:
26 * {
27 * "_id": "bbc44e99-4439-4a51-ac8c-77d6a9bb6243",
28 * "_createdDate": "2021-07-26T06:32:46.466Z",
29 * "_updatedDate": "2021-07-26T06:32:46.467Z",
30 * "revision": 0,
31 * "info": {
32 * "name": {
33 * "first": "Ari",
34 * "last": "Thereyet"
35 * },
36 * "extendedFields": {
37 * "contacts.displayByFirstName": "Ari Thereyet",
38 * "contacts.displayByLastName": "Thereyet Ari"
39 * }
40 * },
41 * "lastActivity": {
42 * "activityDate": "2021-07-26T06:32:46.466Z",
43 * "activityType": "CONTACT_CREATED"
44 * },
45 * "source": {
46 * "appId": "v4.createContact",
47 * "sourceType": "OTHER"
48 * }
49 * }
50 */
Create a new contact, full object

Copy Code
1import { contacts } from 'wix-crm-backend'
2
3export function myCreateContactFunction() {
4 const contactInfo = {
5 name: {
6 first: "Gene",
7 last: "Lopez"
8 },
9 company: "Borer and Sons, Attorneys at Law",
10 jobTitle: "Senior Staff Attorney",
11 locale: "en-US",
12 birthdate: "1981-11-02",
13 profilePicture: "https://randomuser.me/api/portraits/men/0.jpg",
14 emails: [
15 {
16 tag: "WORK",
17 email: "gene.lopez@example.com"
18 },
19 {
20 tag: "HOME",
21 email: "gene.lopez.at.home@example.com",
22 primary: true
23 }
24 ],
25 phones: [
26 {
27 tag: "HOME",
28 countryCode: "US",
29 phone: "(704)-454-1233"
30 },
31 {
32 tag: "MOBILE",
33 countryCode: "US",
34 phone: "(722)-138-3099",
35 primary: true
36 }
37 ],
38 addresses: [
39 {
40 tag: "HOME",
41 address: {
42 streetAddress: {
43 number: "9834",
44 name: "Bollinger Rd"
45 },
46 formatted: "9834 Bollinger Rd\nEl Cajon, WY 97766\nUS",
47 location: {
48 latitude: "84.1048",
49 longitude: "-116.8836"
50 },
51 city: "El Cajon",
52 subdivision: "WY",
53 country: "US",
54 postalCode: "97766"
55 }
56 }
57 ],
58 labelKeys: [
59 "custom.white-glove-treatment",
60 "contacts.contacted-me",
61 "custom.new-lead"
62 ],
63 extendedFields: {
64 "custom.event-we-met-at": "LegalBigData"
65 }
66 };
67
68 const options = {
69 allowDuplicates: false,
70 suppressAuth: false
71 };
72
73 return contacts.createContact(contactInfo, options)
74 .then((contact) => {
75 return contact;
76 })
77 .catch((error) => {
78 console.error(error);
79 });
80}
81
82/* Promise resolves to:
83 * {
84 * "_id": "703d5a66-850d-4ecb-b967-445726a26c15",
85 * "_createdDate": "2021-07-26T07:06:17.685Z",
86 * "_updatedDate": "2021-07-26T07:06:17.686Z",
87 * "revision": 0,
88 * "info": {
89 * "name": {
90 * "first": "Gene",
91 * "last": "Lopez"
92 * },
93 * "profilePicture": "https://randomuser.me/api/portraits/men/0.jpg",
94 * "birthdate": "1981-11-02",
95 * "company": "Borer and Sons, Attorneys at Law",
96 * "jobTitle": "Senior Staff Attorney",
97 * "locale": "en-us",
98 * "emails": [
99 * {
100 * "_id": "ead5f037-515b-4e67-bc77-ac1d70f0cdac",
101 * "tag": "HOME",
102 * "email": "gene.lopez.at.home@example.com",
103 * "primary": true
104 * },
105 * {
106 * "_id": "87a665a4-cde1-4b3c-b164-90e0a7472788",
107 * "tag": "WORK",
108 * "email": "gene.lopez@example.com",
109 * "primary": false
110 * }
111 * ],
112 * "phones": [
113 * {
114 * "_id": "fada6859-e560-4590-a8bf-226a30537701",
115 * "tag": "MOBILE",
116 * "countryCode": "US",
117 * "phone": "(722)-138-3099",
118 * "primary": true
119 * },
120 * {
121 * "_id": "51efdd52-71f3-4562-906d-0c7212599f36",
122 * "tag": "HOME",
123 * "countryCode": "US",
124 * "phone": "(704)-454-1233",
125 * "e164Phone": "+17044541233",
126 * "primary": false
127 * }
128 * ],
129 * "addresses": [
130 * {
131 * "address": {
132 * "formatted": "9834 Bollinger Rd\nEl Cajon, WY 97766\nUS",
133 * "location": {
134 * "latitude": 84.1048,
135 * "longitude": -116.8836
136 * },
137 * "city": "El Cajon",
138 * "subdivision": "US-WY",
139 * "country": "US",
140 * "postalCode": "97766",
141 * "streetAddress": {
142 * "name": "Bollinger Rd",
143 * "number": "9834",
144 * "apt": ""
145 * }
146 * },
147 * "_id": "263e25c5-7f7f-4cab-9a4e-768ca74fd891",
148 * "tag": "HOME"
149 * }
150 * ],
151 * "labelKeys": [
152 * "custom.white-glove-treatment",
153 * "contacts.contacted-me",
154 * "custom.new-lead"
155 * ],
156 * "extendedFields": {
157 * "custom.event-we-met-at": "LegalBigData"
158 * }
159 * },
160 * "primaryInfo": {
161 * "email": "gene.lopez.at.home@example.com",
162 * "phone": "(722)-138-3099"
163 * },
164 * "lastActivity": {
165 * "activityDate": "2021-07-26T07:06:17.685Z",
166 * "activityType": "CONTACT_CREATED"
167 * },
168 * "source": {
169 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a",
170 * "sourceType": "WIX_APP"
171 * }
172 * }
173 */