An event that triggers when a new contact is created.
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.
function onContactCreated(event: ContactCreatedEvent): void;
Information about the contact that was created and metadata for the event.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixCrm_onContactCreated(event) {
const contactId = event.metadata.entityId;
const contactName = `${event.entity.info?.name?.first} ${event.entity.info?.name?.last}`;
console.log("Contact created", event);
}
/* Full event object:
* {
* "metadata": {
* "id": "fde04f82-c5e4-442e-b70e-0fd3f506f2e8",
* "entityId": "bea905ef-d7cb-49b9-bce7-19342d3e7ab3",
* "eventTime": "2021-02-12T00:18:03.097922Z",
* "triggeredByAnonymizeRequest": false
* },
* "entity": {
* "_id": "bea905ef-d7cb-49b9-bce7-19342d3e7ab3",
* "_createdDate": "2021-02-12T00:18:03.045Z",
* "_updatedDate": "2021-02-12T00:18:03.046Z",
* "revision": 0,
* "info": {
* "name": {
* "first": "Ari",
* "last": "Thereyet"
* },
* "extendedFields": {
* "contacts.displayByFirstName": "Ari Thereyet",
* "contacts.displayByLastName": "Thereyet Ari"
* }
* },
* "source": {
* "wixAppId": "v4.createContact"
* },
* "lastActivity": {
* "activityDate": "2021-02-12T00:18:03.045Z",
* "activityType": "CONTACT_CREATED"
* }
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.