Configure onContactCreate and onContactUpdate

onContactCreate

When a contact record is created in the Freshworks system, the onContactCreate event is triggered. In the Freshworks system, an agent can create a new contact and save the details triggering the onContactCreate event. An agent or a requester can raise a ticket; if the contact specified in the ticket does not exist in the Freshworks system, an onContactCreate event is triggered.

Subscribe to the onContactCreate event and register the callback by using the following sample manifest.json content.

manifest.json
"events": {
  "onContactCreate": {
    "handler": "onContactCreateCallback"
  }
}

Define the corresponding callback by using the following sample server.js content:

server.js
exports = {
  onContactCreateCallback: function(payload) {
    console.log("Logging arguments from onContactCreate event: " + JSON.stringify(payload));
  }
}
Sample code
exports = {
  onContactCreateCallback: function(payload) {
    console.log("Logging arguments from onContactCreate event: " + JSON.stringify(payload));
    //Print the new contact and email.
    console.log("Contact name - ", payload.data.contact.name, "\n email - ", payload.data.contact.email);
  }
}

Attributes of the data object

  • actorobject

    Information pertaining to the entity who created the contact record.

  • contactobject

    Information pertaining to the contact (end user/requester/customer)created in the Freshdesk system.

onContactUpdate

The onContactUpdate event is triggered and the registered callback method is executed, when:

  • The following fields of the default contact form are modified.

    • Avatar/Image
    • Full Name
    • Job Title
    • Email
    • Company
    • Twitter ID
    • Work Phone
    • Mobile Phone
    • Address
    • Time Zone
    • Language
    • Unique External ID
    • Tags
    • About

    Note Field names are based on an organization’s configuration of the contact fields and might be different from the above list.

  • The contact is deleted from the Freshworks system.

Subscribe to the onContactUpdate event and register the callback by using the following sample manifest.json content.

manifest.json
"events": {
  "onContactUpdate": {
    "handler": "onContactUpdateCallback"
  }
}

Define the corresponding callback by using the following sample server.js content:

server.js
exports = {
  onContactUpdateCallback: function(payload) {
    console.log("Logging arguments from onContactUpdate event: " + JSON.stringify(payload));
  }
}

Sample code

exports = {
  onContactUpdateCallback: function(payload) {
    console.log("Logging arguments from onContactUpdate event: " + JSON.stringify(payload));
    //Finding fields that are changed.
    var changes = payload.data.contact.changes;
    // Your code to work with changes.
  }
}

Attributes of the data object

  • actorobject

    Information pertaining to the entity who updated the contact record in the Freshdesk system.

  • contactobject

    Information pertaining to the contact (end user/requester/customer) whose details are modified in the Freshdesk system.