We have recently refreshed our branding across our offerings and changed the names of our pricing plans. If you have signed up before Aug 9, 2021, please click Previous plans to view your applicable plans.
We assure you that this change will not impact your product experience, and no action is required on your part.


The Advanced Automations app enables you to set up actions that run on specific triggers when certain conditions are met. The Advanced Automations app is available on the Freshchat marketplace. Click here to check it out. 

For example, you can update create a ticket and update the custom fields on Freshdesk, automatically send Template messages on WhatsApp, etc. 


What you want to achieve

Triggers & Conditions

What the API must do

On resolution, create a ticket in Freshdesk with Custom Fields and tags

Agent resolves a conversation OR System resolves a conversation

Trigger the Freshdesk ticket creation API with values from the conversation and user’s properties to populate the ticket properties


Learn more about setting up the Advance Automations app here.


The actions you set up as part of the automations are executed in the order in which they are listed. The app checks for the first matching automation and runs it. There are different types of actions you can set up as part of the automation. Triggering an API is one of the more powerful and versatile actions. You can set up any request type, specify the API endpoint, any authentication you use, use custom headers, the encoding format, and the information in the content body.


To set up APIs in the Advanced Automations app, you’ll need to first toggle it from Settings > Advanced > APIs and Custom Placeholders. This article will go over setting up the API library that you can use in the Advanced Automations app. You can learn more about using Custom Placeholders here.


Setting up APIs

  1. Before we begin, make sure you have toggled on APIs and Placeholders from Settings > Advanced > APIs and Custom Placeholders.


  2. You can configure all your APIs here in one place, and make use of the APIs multiple times whenever you're setting up any Actions in the Advanced Automations app.

  3. Once you’ve toggled it on, you’ll see the icons for the API library and custom placeholders. Click on the API library icon > Create an API.



  4. Give your API a name and a model name. The API name is for your reference. The model name stores the API response. Use the model name to access the response of the API in other APIs or subsequent actions.

  5. Choose the request type. While each third-party app may use a request type in a different way, most applications follow these standard methods:
    • GET Requests are typically used to retrieve one or all resources.
    • POST Requests usually create new resources.
    • PUT and PATCH Requests are used to update a resource.
    • DELETE Requests are usually used to delete a resource.

  6. Enter the API endpoint URL for the apps to which you are connecting. You can make the URLs dynamic using placeholders.
  7. Choose the authentication that you want to use. You can choose to include custom headers, and API key or a username-password authentication. Custom headers convey information such as security details, API version details, and so on. A custom header has to be entered as a header-value pair following the specified format X-Sample-CustomHeader1: VALUE. 

    Note: 
    The trigger will not be executed when a header is given with spaces in between, like X-Sample Custom Header1: VALUE. Although, if a space is entered at the end of the header, it will be skipped.

    • A header containing more than one value should be separated by delimiters (commas and colons cannot be used as delimiters). To add a second header, enter the custom header and value pair in the next line.

  8. You can use any of the existing default placeholders or make it dynamic using custom placeholders that you have set up for these authentication fields. You can read more about using custom placeholders here.

    Note:
    While we offer the Freshdesk integration out of the box for the Advanced Automations app, you can use it with any other product too. Define custom placeholders with the authentication information to use them in APIs as part of an Action.

  9. Pick your choice of encoding between XML, JSON, and X-FORM-URLENCODED. Based on your choice, the Advanced Automations app will validate the content body. For example, if you pick JSON, the content body needs to be a valid JSON format, or else an error message will show up.

  10. Click done once you’re done.

Setting up automations with API triggers

  1. On the automations screen, either create a new automation or edit existing automations.

  2. Set up the trigger and any conditions that you require.

  3. In the Actions screen, choose “trigger an API” and the Advanced Automations app will show you the list of APIs in your API library.

Note: You can define an API once and use it many times with different automations.


Here's an example

Let’s take a closer look at this with an example. In this example, we have already set up two APIs.



  • The first API creates a ticket on Freshdesk, while the second API adds a reply to the same Freshdesk ticket.

  • The second API will use the ticket ID that is part of the response of the first API using the model name.

  • Setting up the freshdesk_ticket API is the same as detailed earlier in this article. While setting up the second API, we will have to make sure it refers to the model name from the first API. 


Note: You can create the APIs in any order. But when you use APIs in Actions, the Actions will execute in the order in which they are used. So, if one API fails, any subsequent APIs and Actions that are dependent on the first one will also fail.


The second API uses the URL field to lookup the ticket ID, which is part of the response object from Freshdesk when a ticket is created.


Note: You can look up any of the properties that are part of the response objects in another API response.


For example, when you use the create ticket API, Freshdesk offers the following properties in the response object:


{
"cc_emails" : ["ram@freshdesk.com", "diana@freshdesk.com"],
"fwd_emails" : [ ],
"reply_cc_emails" : ["ram@freshdesk.com", "diana@freshdesk.com"],
"email_config_id" : null,
"group_id" : null,
"priority" : 1,
"requester_id" : 129,
"responder_id" : null,
"source" : 2,
"status" : 2,
"subject" : "Support needed..",
"company_id" : 1,
"id" : 1,
"type" : "Question",
"to_emails" : null,
"product_id" : null,
"fr_escalated" : false,
"spam" : false,
"urgent" : false,
"is_escalated" : false,
"created_at" : "2015-07-09T13:08:06Z",
"updated_at" : "2015-07-23T04:41:12Z",
"due_by" : "2015-07-14T13:08:06Z",
"fr_due_by" : "2015-07-10T13:08:06Z",
"description_text" : "Some details on the issue ...",
"description" : "<div>Some details on the issue ..</div>",
"tags" : [ ],
"attachments" : [ ]
}


  • Similarly, the API you use will return a set of properties in the response object, and you can use any of them in subsequent API calls with the model name.

  • Any properties that are already defined in Freshchat can be directly picked up and inserted. But if you want to use any properties in the response object from an external system, you’ll need to lookup based on the response object.


HandlebarsJS

We use Handlebars JS [https://handlebarsjs.com/] to enable the lookup option to refer to the response of one API from another. It’s a powerful templating technology that we’ve built into the Advanced Automations app. You can use any of the built-in helpers from Handlebars JS (which includes lookup).


For example, you can use an if loop to get the information about what tags are used in Freshdesk as individual strings instead of an array (which is how tags are returned in Freshdesk’s create ticket API response).


Additionally, you can also get an add-on called handlebars-helpers [https://www.npmjs.com/package/handlebars-helpers], which adds more than 130 helpers to your toolkit. This enables you to carry out almost any logical process that you would want to do. Here are some examples:

  • You can use complex equations which involve multiple and-or conditions
  • You can convert strings into numbers, decimals, or even set up comparisons between multiple values
  • You can print dates from the UTC format to any supported human-readable format


This is a powerful templating technology that you can use in the Advanced Automations app.