Search.../

onContactCreated( )

Developer Preview

An event that triggers when a new contact is created.

Description

The onContactCreated() event handler runs when a new contact is created. The received ContactCreatedEvent object contains information about the contact that was created.

Note: Backend events don't work when previewing your site.

Syntax

function wixCrm_onContactCreated(event: ContactCreated): void

onContactCreated Parameters

NAME
TYPE
DESCRIPTION
event
Optional
ContactCreated

Information about the contact that was created and metadata for the event.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

An event fired when a contact is created

Copy Code
1// Place this code in the events.js file
2// of your site's Backend section.
3// Add the file if it doesn't exist.
4
5export function wixCrm_onContactCreated(event) {
6 const eventId = event.metadata.id;
7 const entityId = event.entity._id;
8 const lastName = event.entity.info.name.last;
9}
10
11/* Full event object:
12 * {
13 * "metadata": {
14 * "id": "7bdca23b-a89c-48a1-be76-6dcf46fc4edb",
15 * "entityId": "beeb8dc1-93d6-49f3-9389-18a9997f554f",
16 * "eventTime": "2024-01-10T10:30:27.479909037Z",
17 * "triggeredByAnonymizeRequest": false
18 * },
19 * "entity": {
20 * "_id": "beeb8dc1-93d6-49f3-9389-18a9997f554f",
21 * "revision": 1,
22 * "source": {
23 * "sourceType": "ADMIN"
24 * },
25 * "_createdDate": "2024-01-10T10:30:27.447Z",
26 * "_updatedDate": "2024-01-10T10:30:27.447Z",
27 * "primaryInfo": {
28 * "email": "fforte@example.com",
29 * "phone": "646-446-4789"
30 * },
31 * "lastActivity": {
32 * "activityDate": "2024-01-10T10:30:27.446Z",
33 * "activityType": "CONTACT_CREATED"
34 * },
35 * "info": {
36 * "name": {
37 * "first": "Forrest",
38 * "last": "Forte"
39 * },
40 * "emails": [
41 * {
42 * "tag": "UNTAGGED",
43 * "email": "fforte@example.com",
44 * "primary": true,
45 * "_id": "c27570d4-fc36-4391-aeb4-216b65ebb5e9"
46 * },
47 * {
48 * "tag": "UNTAGGED",
49 * "email": "forrest.forte@example.com",
50 * "primary": false,
51 * "_id": "5377214c-d6da-4212-aa8b-2735f0ad71e7"
52 * }
53 * ],
54 * "phones": [
55 * {
56 * "tag": "MOBILE",
57 * "countryCode": "US",
58 * "phone": "646-446-4789",
59 * "e164Phone": "+16464464789",
60 * "formattedPhone": "+1 646-446-4789",
61 * "primary": true,
62 * "_id": "412ccdb6-b5de-441f-ad9f-a32637357c98"
63 * },
64 * {
65 * "tag": "WORK",
66 * "countryCode": "US",
67 * "phone": "718-250-2680",
68 * "e164Phone": "+17182502680",
69 * "formattedPhone": "+1 718-250-2680",
70 * "primary": false,
71 * "_id": "90148d5d-4940-4761-9a30-6c677c92fa3e"
72 * }
73 * ],
74 * "addresses": [
75 * {
76 * "_id": "19d2ab15-0c8e-4f2c-894a-eddaba1088cf",
77 * "tag": "BILLING",
78 * "address": {
79 * "formatted": "82 Howard Ave\nNew York, New York 11598\nUnited States",
80 * "subdivision": "US-NY",
81 * "city": "New York",
82 * "country": "US",
83 * "postalCode": "11598",
84 * "addressLine1": "82 Howard Ave"
85 * }
86 * }
87 * ],
88 * "labelKeys": [
89 * "contacts.customers"
90 * ],
91 * "extendedFields": {
92 * "custom.age": 43,
93 * "invoices.vatId": "",
94 * "contacts.displayByFirstName": "Forrest Forte",
95 * "contacts.displayByLastName": "Forte Forrest"
96 * }
97 * }
98 * }
99 * }
100 */
101