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

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