Product events are Freshdesk events such as ticket create, ticket update, and note create that trigger backend apps. When these events occur, the appropriate method within the server.js file of a backend app is called.
Note:
1. You need to have SDK v2.3.1 or higher in order to use this feature. You can find instructions on how to get the latest version here.
2. Backend apps will be executed in a sandboxed mode and hence functions such as setTimeout, require cannot be used.
Payload
When a supported product event occurs, the corresponding method in the server.js is invoked and the following payload is passed to the app to enable it to get context about the event.
Copied Copy1 2 3 4 5 6 7 8 9 10 11 12 | { "account_id" : value, "domain" : "value", "event" : "value", "data" : { //“data” contains the list of objects related to the event. }, "iparams" : { "Param1" : "value", "Param2" : "value" } } |
Attribute | Type | Description |
---|---|---|
account_id | number | Freshdesk account ID |
domain | string | Freshdesk account domain |
event | string | Name of the event |
iparams | object | Installation Parameters |
Registration
In order for the appropriate method to be called when a product event occurs, an event listener should be added. This should be done in the format as shown in the sample below.
server.js Copied Copy
1 2 3 4 5 6 7 8 9 | exports = { events: [ { event: "eventName", callback: "eventCallbackMethod" } ], eventCallbackMethod: function(payload) { //Multiple events can access the same callback console.log("Logging arguments from the event: " + JSON.stringify(payload)); } } |
Note:
1. You should include the event and the callback definition within the exports block.
2. You should include only one callback function for an event.
3. You should only use valid keys - “event” and “callback”, usage of other keys will throw an error.
4. Provide a valid event name, incorrect names will lead to an error.
onTicketCreate
This event will be invoked every time a new ticket is created. The registered callback method for this event will be executed in response to this event.
You should follow the below format to include the event in the server.js:
Copied Copy1 2 3 4 5 6 7 8 | exports = { events: [ { event: "onTicketCreate", callback: "onTicketCreateCallback" } ], onTicketCreateCallback: function(payload) { console.log("Logging arguments from onTicketCreate event: " + JSON.stringify(payload)); } } |
Sample Code Copied Copy
1 2 3 4 5 6 7 8 9 10 11 12 | exports = { events: [ { event: "onTicketCreate", callback: "onTicketCreateCallback" } ], onTicketCreateCallback: function(payload) { console.log("Logging arguments from onTicketCreate event: " + JSON.stringify(payload)); if(payload.data.ticket.priority >= 3) { //your code goes here } } } |
Sample Payload
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | { "account_id" : 13, "domain" : "sample.freshdesk.com", "event" : "onTicketCreate", "data" : { "ticket": { "subject": "Support Needed...", "description": "<div>Some details on the issue ..</div>", "is_description_truncated": false, "description_text": "Some details on the issue ...", "is_description_text_truncated": false, "due_by": "2015-07-14T13:08:06Z", "fr_due_by": "2015-07-14T13:08:06Z", "fr_escalated": false, "is_escalated": false, "fwd_emails": ["ram@freshdesk.com", "diana@freshdesk.com"], "reply_cc_emails": ["ram@freshdesk.com", "diana@freshdesk.com"], "email_config_id": 77123, "id": 1, "group_id": 351, "product_id": 1, "company_id": 2, "requester_id": 5483, "responder_id": 320, "tweet_id": "01234567890123456789", "status": 2, "priority": 1, "type": "Question", "tags": ["sales", "marketing"], "spam": false, "source": 2, "cc_emails": ["ram@freshdesk.com", "diana@freshdesk.com"], "to_emails": ["ram@freshdesk.com", "diana@freshdesk.com"], "created_at": "2015-07-09T13:08:06Z", "updated_at": "2015-07-09T13:08:06Z", "attachments": [ { "id": 9019290053, "content_type": "image/jpeg", "file_size": 78942, "name": "sample.jpg", "attachment_url": "https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/9019290053/original/sample.jpg", "created_at": "2016-12-22T09:37:47Z", "updated_at": "2016-12-22T09:37:47Z" } ] }, "requester": { "id": 5483, "name": "Rachel", "email": "rachel@freshdesk.com", "mobile": 7654367287, "phone": 4352789885, "language": "en", "created_at": "2015-08-28T09:08:16Z" } } "iparams" : null } |
The following table lists the attributes of the ticket object:
ATTRIBUTE | TYPE | DESCRIPTION |
---|---|---|
attachments | array of objects | Ticket attachments |
created_at | datetime |
Ticket creation timestamp in the UTC format, YYYY-MM-DDTHH:MM:SSZ. Example : 2016-02-13T23:27:49Z |
company_id | number | ID of the company to which this ticket belongs |
cc_emails | array of strings | Email addresses added in the 'cc' field of the incoming ticket email |
description | string | HTML content of the ticket description. This content will be truncated if it exceeds 10KB. |
is_description_truncated | boolean | Set to true if the description is truncated. |
description_text | string | Content of the ticket description in plain text. This content will be truncated if it exceeds 10KB. |
is_description_text_truncated | boolean | Set to true if the description_text is truncated. |
due_by | datetime |
Timestamp that denotes when the ticket is due to be resolved. Timestamp will be in the UTC format, YYYY-MM-DDTHH:MM:SSZ. Example: 2016-02-13T23:27:49Z |
email_config_id | number | ID of email config which is used for this ticket |
tweet_id | string | ID of the Tweet that was converted into a ticket. |
fr_due_by | datetime |
Timestamp that denotes when the first response is due. Timestamp will be in the UTC format, YYYY-MM-DDTHH:MM:SSZ. Example: 2016-02-13T23:27:49Z |
fr_escalated | boolean | Set to true if the ticket has been escalated as the result of first response time being breached |
fwd_emails | array of strings | Email address(es) added while forwarding a ticket |
group_id | number | ID of the group to which the ticket has been assigned |
id | number | Unique ID of the ticket |
is_escalated | boolean | Set to true if the ticket has been escalated for any reason |
priority | number | Priority of the ticket |
product_id | number | ID of the product to which the ticket is associated |
reply_cc_emails | array of strings | Email address(es) added while replying to a ticket |
requester_id | number | User ID of the requester. For existing contacts, the requester_id can be passed instead of the requester's email |
responder_id | number | ID of the agent to whom the ticket has been assigned |
source | number | The channel through which the ticket was created |
spam | boolean | Set to true if the ticket has been marked as spam |
status | number | Status of the ticket |
subject | string | Subject of the ticket |
tags | array of strings | Returns the list of tags for a ticket |
type | string | Helps categorize the ticket according to the different kinds of issues your support team deals with |
to_emails | array of strings | Email addresses to which the ticket was originally sent |
updated_at | datetime | Ticket updated timestamp in the UTC format, YYYY-MM-DDTHH:MM:SSZ Example: 2016-02-13T23:27:49Z |
Every ticket uses certain fixed numerical values to denote its source, status, and priority. These numerical values along with their meanings are given below.
Source | Value |
---|---|
1 | |
Portal | 2 |
Phone | 3 |
5 | |
6 | |
Chat | 7 |
Mobihelp | 8 |
Feedback Widget | 9 |
Outbound Email | 10 |
Status | Value |
---|---|
Open | 2 |
Pending | 3 |
Resolved | 4 |
Close | 5 |
Priority | Value |
---|---|
Low | 1 |
Medium | 2 |
High | 3 |
Urgent | 4 |
The following table lists the attributes of the requester object:
ATTRIBUTE | TYPE | DESCRIPTION |
---|---|---|
id | number | ID of the Requester |
name | string | Name of the Requester |
string | Primary email of the Requester | |
mobile | number | Mobile number of the Requester |
phone | string | Telephone number of the Requester |
language | string | Language of the requester/contact, by default, language is "en". |
created_at | datetime | Contact creation timestamp |
onTicketUpdate
This event will be invoked every time a ticket property is updated. You can provide the action to be performed in the callback method, this code will be executed in response to this event trigger.
Following are the supported ticket update events:
- Status changed
- Priority changed
- Group changed
- Agent changed
- Ticket deleted
- Ticket is marked as spam
- Type changed
- Source changed
- Ticket is escalated for any reason
- Ticket is escalated because first response was breached
Note:
1. Ticket update only happens for updates to the ticket properties and a few other fields. Replies or note additions are not considered ticket updates, you need to use the onConversationCreate event to handle them.
2. Ticket deletion updates will be captured by the onTicketUpdate event and the changes object will note that the deleted boolean has been changed from false to true.
Restrictions
The following changes will NOT trigger a ticket update event:
- Any updates made to custom fields.
- Any updates to tags.
You should follow the below format to include the event in the server.js:
Copied Copy1 2 3 4 5 6 7 8 | exports = { events: [ { event: "onTicketUpdate", callback: "onTicketUpdateCallback" } ], onTicketUpdateCallback: function(payload) { console.log("Logging arguments from onTicketUpdate event: " + JSON.stringify(payload)); } } |
Sample Code Copied Copy
1 2 3 4 5 6 7 8 9 10 11 | exports = { events: [ { event: "onTicketUpdate", callback: "onTicketUpdateCallback" } ], onTicketUpdateCallback: function(payload) { console.log("Logging arguments from onTicketUpdate event: " + JSON.stringify(payload)); //Finding fields that are changed var changes = payload.data.ticket.changes; //Your code goes here } } |
Sample Payload
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | { "data" : { "ticket": { "subject": "Support Needed...", "description": "<div>Some details on the issue ..</div>", "is_description_truncated": false, "description_text": "Some details on the issue ...", "is_description_text_truncated": false, "due_by": "2015-07-14T13:08:06Z", "fr_due_by": "2015-07-14T13:08:06Z", "fr_escalated": false, "is_escalated": false, "fwd_emails": ["ram@freshdesk.com", "diana@freshdesk.com"], "reply_cc_emails": ["ram@freshdesk.com", "diana@freshdesk.com"], "email_config_id": 77123, "id": 1, "group_id": 351, "product_id": 1, "company_id": 2, "requester_id": 5483, "responder_id": 320, "tweet_id": "01234567890123456789", "status": 2, "priority": 1, "type": "Question", "tags": ["sales", "marketing"], "spam": false, "source": 2, "cc_emails": ["ram@freshdesk.com", "diana@freshdesk.com"], "to_emails": ["ram@freshdesk.com", "diana@freshdesk.com"], "created_at": "2015-07-09T13:08:06Z" , "updated_at": "2015-07-09T13:08:06Z", "attachments": [ { "id": 9019290053, "content_type": "image/jpeg", "file_size": 78942, "name": "sample.jpg", "attachment_url": "https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/9019290053/original/sample.jpg", "created_at": "2016-12-22T09:37:47Z", "updated_at": "2016-12-22T09:37:47Z" } ], "changes": { "source": [2, 3], "priority": [1, 2] } }, "requester": { "id": 5483, "name": "Rachel", "email": "rachel@freshdesk.com", "mobile": 7654367287, "phone": 4352789885, "language": "en", "created_at": "2015-03-28T09:08:16Z" } } |
When a ticket is deleted, a boolean field "deleted" will be set to true as shown in the below sample:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | { "account_id": 129, "domain": "fdm71.freshpacket.com", "event": "onTicketUpdate", "data": { "ticket": { "subject": "Support for ..", "description": "<div>Some details on the issue ..</div>", "is_description_truncated": false, "description_text": "Some details on the issue ...", "is_description_text_truncated": false, "due_by": 1484825400, "fr_due_by": "2017-01-17T17:00:00+05:30", "fr_escalated": false, "is_escalated": false, "fwd_emails": [], "reply_cc_emails": [], "email_config_id": null, "tweet_id": "01234567890123456789", "id":105, "group_id": null, "product_id": null, "company_id": null, "requester_id": 3877, "responder_id": null, "status": 6, "priority": 1, "type": null, "tags": null, "spam": false, "source": 3, "cc_emails": [], "to_emails": null, "created_at": 1484557933, "updated_at": "2017-01-17T17:52:18+05:30", "attachments": [], "changes": { "deleted": [false,true] } }, "requester": { "id": 3877, "name": "Regh", "email": "regh@gmail.com", "mobile": null, "phone": null, "language": "en", "created_at": "2015-03-28T09:08:16Z" } } "iparams": null } |
The changes field is passed along with the payload, this field consist of updated keys with old and new values.
The following table lists the attributes of the ticket object:
ATTRIBUTE | TYPE | DESCRIPTION |
---|---|---|
attachments | array of objects | Ticket attachments |
changes | dictionary | Updated keys with old and new values |
created_at | datetime |
Ticket creation timestamp in the UTC format, YYYY-MM-DDTHH:MM:SSZ. Example : 2016-02-13T23:27:49Z |
company_id | number | ID of the company to which this ticket belongs |
cc_emails | array of strings | Email addresses added in the 'cc' field of the incoming ticket email |
description | string | HTML content of the ticket description. This content will be truncated if it exceeds 10KB. |
is_description_truncated | boolean | Set to true if the description is truncated. |
description_text | string | Content of the ticket description in plain text. This content will be truncated if it exceeds 10KB. |
is_description_text_truncated | boolean | Set to true if the description_text is truncated. |
due_by | datetime |
Timestamp that denotes when the ticket is due to be resolved. Timestamp will be in the UTC format, YYYY-MM-DDTHH:MM:SSZ. Example: 2016-02-13T23:27:49Z |
email_config_id | number | ID of email config which is used for this ticket. |
tweet_id | string | ID of the Tweet that was converted into a ticket. |
fr_due_by | datetime |
Timestamp that denotes when the first response is due. Timestamp will be in the UTC format, YYYY-MM-DDTHH:MM:SSZ. Example: 2016-02-13T23:27:49Z |
fr_escalated | boolean | Set to true if the ticket has been escalated as the result of first response time being breached |
fwd_emails | array of strings | Email address(es) added while forwarding a ticket |
group_id | number | ID of the group to which the ticket has been assigned |
id | number | Unique ID of the ticket |
is_escalated | boolean | Set to true if the ticket has been escalated for any reason |
priority | number | Priority of the ticket |
product_id | number | ID of the product to which the ticket is associated |
reply_cc_emails | array of strings | Email address(es) added while replying to a ticket |
requester_id | number | User ID of the requester. For existing contacts, the requester_id can be passed instead of the requester's email |
responder_id | number | ID of the agent to whom the ticket has been assigned |
source | number | The channel through which the ticket was created |
spam | boolean | Set to true if the ticket has been marked as spam |
status | number | Status of the ticket |
subject | string | Subject of the ticket |
tags | array of strings | Returns the list of tags for a ticket |
type | string | Helps categorize the ticket according to the different kinds of issues your support team deals with |
to_emails | array of strings | Email addresses to which the ticket was originally sent |
updated_at | datetime | Ticket updated timestamp in the UTC format, YYYY-MM-DDTHH:MM:SSZ. Example: 2016-02-13T23:27:49Z |
Every ticket uses certain fixed numerical values to denote its source, status, and priority. These numerical values along with their meanings are given below.
Source | Value |
---|---|
1 | |
Portal | 2 |
Phone | 3 |
5 | |
6 | |
Chat | 7 |
Mobihelp | 8 |
Feedback Widget | 9 |
Outbound Email | 10 |
Status | Value |
---|---|
Open | 2 |
Pending | 3 |
Resolved | 4 |
Close | 5 |
Priority | Value |
---|---|
Low | 1 |
Medium | 2 |
High | 3 |
Urgent | 4 |
The following table lists the attributes of the requester object:
ATTRIBUTE | TYPE | DESCRIPTION |
---|---|---|
id | number | ID of the Requester |
name | string | Name of the Requester |
string | Primary email of the Requester | |
mobile | number | Mobile number of the Requester |
phone | string | Telephone number of the Requester |
language | string | Language of the requester/contact, by default, language is "en". |
created_at | datetime | Contact creation timestamp |
onConversationCreate
This event will be invoked every time a reply or note is added to a ticket. You can provide the action to be performed in the callback method, this code will be executed in response to this event trigger.
Following are the supported conversation create events:
- Reply added
- Public note added
- Private note added
The format to include the event in the server.js:
Copied Copy1 2 3 4 5 6 7 8 | exports = { events: [ { event: "onConversationCreate", callback: "onConversationCreateCallback" } ], onConversationCreateCallback: function(payload) { console.log("Logging arguments from onConversationCreate event: " + JSON.stringify(payload)); } } |
Sample Reply Payload
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | { "account_id" : 13, "domain" : "http://sample.freshdesk.com", "event" : "onConversationCreate", "data": { "conversation": { "body": "<div>Hi tom, Still Angry</div>", "is_body_truncated": false, "body_text": "Hi tom, Still Angry", "is_body_text_truncated": false, "id": 5, "from_email": "rachel@freshdesk.com", "bcc_emails": ["ram@freshdesk.com", "diana@freshdesk.com"], "support_email": "rachel@freshdesk.com", "user_id": 23423, "ticket_id": 452, "private": false, "incoming": false, "source": 0, "cc_emails": null, "to_emails": ["ram@freshdesk.com", "diana@freshdesk.com"], "created_at": "2015-07-09T13:08:06Z", "updated_at": "2015-07-09T13:08:06Z", "attachments": [ { "id": 9019290053, "content_type": "image/jpeg", "size": 78942, "name": "sample.jpg", "attachment_url": "https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/9019290053/original/sample.jpg", "created_at": "2016-12-22T09:37:47Z", "updated_at": "2016-12-22T09:37:47Z" } ] } } "iparams" : null } |
Sample Public Note Payload
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | { "account_id" : 13, "domain" : "http://sample.freshdesk.com", "event" : "onConversationCreate", "data": { "conversation": { "body": "<div>Hi tom, Still Angry</div>", "is_body_truncated": false, "body_text": "Hi tom, Still Angry", "is_body_text_truncated": false, "id": 5, "from_email": null, "bcc_emails": [], "support_email": null, "user_id": 23423, "ticket_id": 452, "private": false, "incoming": false, "source": 2, "cc_emails": null, "to_emails": [], "created_at": "2015-07-09T13:08:06Z", "updated_at": "2015-07-09T13:08:06Z", "attachments": [] } } "iparams" : null } |
Sample Private Note Payload
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | { "account_id" : 13, "domain" : "http://sample.freshdesk.com" "event" : "onConversationCreate", "data": { "conversation": { "body": "<div>Hi tom, Still Angry</div>", "is_body_truncated": false, "body_text": "Hi tom, Still Angry", "is_body_text_truncated": false, "id": 5, "from_email": null, "bcc_emails": [], "support_email": null, "user_id": 23423, "ticket_id": 452, "private": true, "incoming": true, "source": 2, "cc_emails": null, "to_emails": [], "created_at": "2015-07-09T13:08:06Z", "updated_at": "2015-07-09T13:08:06Z", "attachments": [] } } "iparams" : null } |
The following table lists the attributes of the conversation object:
ATTRIBUTE | TYPE | DESCRIPTION |
---|---|---|
attachments | array of objects | Attachments associated with the conversation |
body | string | Content of the conversation in HTML. This content will be truncated if it exceeds 10KB. |
is_body_truncated | boolean | Set to true if the body is truncated. |
body_text | string | Content of the conversation in plain text. This content will be truncated if it exceeds 10KB. |
is_body_text_truncated | boolean | Set to true if the body_text is truncated. |
bcc_emails | array of strings | Email address added in the 'bcc' field of the outgoing ticket email |
cc_emails | array of strings | Email addresses added in the 'cc' field of the incoming ticket email |
created_at | datetime | Conversation creation timestamp in the UTC format, YYYY-MM-DDTHH:MM:SSZ. Example: 2016-02-13T23:27:49Z |
from_email | string | The email address from which the reply is sent. By default, the global support email will be used. |
id | number | Unique ID of the conversation |
incoming | boolean | Set to true if a particular conversation should appear as being created from outside (i.e., not through a web portal) |
private | boolean | Set to true if it is a private note |
private | boolean | Set to true if it is a private note |
source | number | Denotes the type of the conversation |
supporting_email | string | Email address from which the reply is sent. For notes, this value will be null. |
ticket_id | number | ID of the ticket to which the conversation is being added |
to_emails | array of strings | Email addresses of agents/users who need to be notified about this conversation |
updated_at | datetime | Ticket updated timestamp in the UTC format, YYYY-MM-DDTHH:MM:SSZ Example: 2016-02-13T23:27:49Z |
user_id | number | ID of the agent/user who is adding the conversation |
Every conversation uses certain fixed numerical values to denote its source. These numerical values along with their meanings are given below.
Source | Value |
---|---|
Reply | 0 |
Note | 2 |
Created from tweets | 5 |
Created from survey feedback | 6 |
Created from Facebook post | 7 |
Source | Value |
---|---|
Created from Forwarded Email | 8 |
Created from Phone | 9 |
Created from Mobihelp | 10 |
E-Commerce | 11 |
onContactCreate
This event will be invoked every time a contact is created. You can provide the action to be performed in the callback method, this code will be executed in response to this event trigger.
You should follow the below format to include the event in the server.js:
Copied Copy1 2 3 4 5 6 7 8 | exports = { events: [ { event: "onContactCreate", callback: "onContactCreateCallback" } ], onContactCreateCallback: function(payload) { console.log("Logging arguments from onContactCreate event: " + JSON.stringify(payload)); } } |
Sample Code Copied Copy
1 2 3 4 5 6 7 8 9 10 | exports = { events: [ { event: "onContactCreate", callback: "onContactCreateCallback" } ], onContactCreateCallback: function(payload) { console.log("Logging arguments from onContactCreate event: " + JSON.stringify(payload)); //Print the new contact and his email. console.log(“Contact name - “, payload.data.contact.name, “\n email - ”, payload.data.contact.email); } } |
Sample Payload
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | { "account_id" : 13, "domain" : "http://sample.freshdesk.com", "event" : "onContactCreate", "data": { "contact": { "active": false, "address": "221 B, Baker Street, London.", "company_id": 1, "description": "Sherlocks contact details.", "email": "superman@freshdesk.com", "id": 2, "job_title": "Investigator", "language": "en", "mobile": 3545643254, "name": "Sherlock Holmes", "phone": "98765315", "time_zone": "London", "twitter_id": "234xsdf", "other_emails": ["lex@freshdesk.com","louis@freshdesk.com"], "created_at": "2015-08-28T09:08:16Z", "updated_at": "2015-08-28T09:08:16Z", "tags": ["marketing"], "custom_fields": { "external_id": 1289 } } }, "iparams" : null } |
The following table lists the attributes of the contact object:
ATTRIBUTE | TYPE | DESCRIPTION |
---|---|---|
active | boolean | Set to true if the contact has been verified |
address | string | Address of the contact |
company_id | number | ID of the company to which this contact belongs |
custom_fields | dictionary | Key value pairs containing the names and values of custom fields. |
description | string | A small description of the contact |
string | Primary email address of the contact. If you want to associate additional email(s) with this contact, use the other_emails attribute. | |
id | number | ID of the contact |
job_tittle | string | Job title of the contact |
language | string | Language of the requester/contact, by default, language is "en". |
mobile | number | Mobile number of the contact |
name | string | Name of the contact |
phone | string | Telephone number of the contact |
time_zone | string | Time zone of the contact. Default value is the time zone of the domain. This attribute can only be set if the Multiple Time Zone feature is enabled (Garden plan and above) |
other_emails | array of strings | Additional emails associated with the contact |
twitter_id | string | Twitter handle of the contact |
created_at | datetime | Contact creation timestamp |
updated_at | datetime | Contact creation timestamp |
tags | array of strings | Tags associated with this contact |
onContactUpdate
This event will be invoked every time a contact is updated. You can provide the action to be performed in the callback method, this code will be executed in response to this event trigger.
Following are the supported contact update events:
- Contact details changed
- Contact deleted
- Contact blocked
- Contact whitelisted
- Contact tags added/updated/deleted
- Contact activated
Note:
Updating a contact to an agent will not trigger this event.
You should follow the below format to include the event in the server.js:
Copied Copy1 2 3 4 5 6 7 8 | exports = { events: [ { event: "onContactUpdate", callback: "onContactUpdateCallback" } ], onContactUpdateCallback: function(payload) { console.log("Logging arguments from onContactUpdate event: " + JSON.stringify(payload)); } } |
Sample Code Copied Copy
1 2 3 4 5 6 7 8 9 10 11 | exports = { events: [ { event: "onContactUpdate", callback: "onContactUpdateCallback" } ], 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. } } |
Sample Payload
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | { "account_id" : 13, "domain" : "http://sample.freshdesk.com", "events" : "onContactUpdate", "data": { "contact": { "active": false, "address": "221 B, Baker Street, London.", "company_id": 1, "description": "Sherlocks contact details.", "email": "superman@freshdesk.com", "id": 2, "job_title": "Investigator", "language": "en", "mobile": 3545643254, "name": "Sherlock Holmes", "phone": "987653151", "time_zone": "London", "twitter_id": "234xsdf", "other_emails": ["lex@freshdesk.com","louis@freshdesk.com"], "created_at": "2015-08-28T09:08:16Z", "updated_at": "2015-08-28T09:08:16Z", "tags": ["marketing"], "custom_fields": { "external_id": 1289 }, "changes": { "phone": ["98765315", "987653151"] } } }, "iparams" : null } |
The changes field is passed along with the payload, this field consist of updated keys with old and new values.
When a contact is deleted, a boolean field "deleted" will be set to true as shown in the below sample:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | { "account_id" : 13, "domain" : "http://sample.freshdesk.com", "events" : "onContactUpdate", "data": { "contact": { "active": false, "address": "221 B, Baker Street, London.", "company_id": 1, "description": "Sherlocks contact details.", "email": "superman@freshdesk.com", "id": 2, "job_title": "Investigator", "language": "en", "mobile": 3545643254, "name": "Sherlock Holmes", "phone": "987653151", "time_zone": "London", "twitter_id": "234xsdf", "other_emails": ["lex@freshdesk.com","louis@freshdesk.com"], "created_at": "2015-08-28T09:08:16Z", "updated_at": "2015-08-28T09:08:16Z", "tags": ["marketing"], "custom_fields": { "external_id": 1289 }, "changes": { "deleted": [false,true] } } } "iparams" : null } |
The following table lists the attributes of the contact object:
ATTRIBUTE | TYPE | DESCRIPTION |
---|---|---|
active | boolean | Set to true if the contact has been verified |
address | string | Address of the contact |
changes | dictionary | Updated keys with old and new values |
company_id | number | ID of the company to which this contact belongs |
custom_fields | dictionary | Key value pairs containing the names and values of custom fields. |
description | string | A small description of the contact |
string | Primary email address of the contact. If you want to associate additional email(s) with this contact, use the other_emails attribute. | |
id | number | ID of the contact |
job_tittle | string | Job title of the contact |
language | string | Language of the requester/contact, by default, language is "en". |
mobile | number | Mobile number of the contact |
name | string | Name of the contact |
phone | string | Telephone number of the contact |
time_zone | string | Time zone of the contact. Default value is the time zone of the domain. This attribute can only be set if the Multiple Time Zone feature is enabled (Garden plan and above) |
other_emails | array of strings | Additional emails associated with the contact |
twitter_id | string | Twitter handle of the contact |
created_at | datetime | Contact creation timestamp |
updated_at | datetime | Contact creation timestamp |
tags | array of strings | Tags associated with this contact |