Engati - User Guide
...
Building Your Bot
Configuring Integrations

JSON API

11min

Engati provides a strong capability to integrate with any system using REST APIs with JSON as the data exchange format.

JSON (JavaScript Object Notation) is the most widely used data format for data interchange on the web.

You can easily integrate with other CRMs and your databases via this node.

  • I have used an API that is JSON-based. 
  • In this example, I am fetching data from an API. 
  • I am storing the data from the API response in a new attribute.
  • I am displaying the data from the attribute to the end-user

Methods



GET    –   This method is used to read data

POST  –   This method is used to update data

PUT    –    This method is used to write or update data

DELETE  – This method is used to delete the data

For the POST and PUT method, you can use the JSON API node to make an API request to update or write data,

this data can be user-entered or predefined by the bot admin. You have to add JSON data in the Body field.

Params 

  • The Params tab helps you edit the data required for URL parameters.
  • When you add key-value pairs, the JSON API Plugin automatically combines it with the URL while making the API call.
  • The value of the parameter can be user-entered or predefined by the bot admin.

If you want to pass parameters from the user’s side you will have to save the user input as an attribute in the bot and later access it in the JSON API node by typing “{“ in the Params value field.

Headers

  • You can add headers to your API request which can again be user-entered data or predefined by the bot admin. 
  • You can pass authentication tokens, app secrets, passwords, and other credentials as per the requirements of the end-point.

Authentication

Authenticate allows you to define identification parameters along with the endpoint. 

The authenticate tab provides you with ways to add different types of API authentication to your API request. The supported types are :

  1. Key Based API Authentication
  2. Basic Authentication
  3. Token-Based Authentication (Two-Step Authentication)

You can select “None” as authentication if no authentication is required which is by default. 



Key Based Auth

For requests that require Key Based API Authentication, you can simply include the authentication keys or an already saved token variable in params/headers.



Basic Auth

For Basic Authentication, you can enter your username and password. It automatically adds the required “Authorization” header to your API request.

How to use Basic Authentication?

  • In the Authentication tab, select “Basic” from the Authentication Type drop-down menu.
  • To set the authentication parameters for a request, enter your username and password or user the details from the list of variables saved.
  • Click the Send button to test your API with basic authentication.
  • In the case of an Auth failure (i.e. response code 401), it executes the path that you specify under Input Path which can be structured in a way to simply update the username/password variables.



Token-Based Authentication (Two-Step Authentication)

How to use Token-Based Authentication?

  • In the authentication tab, select “Token” from the Authentication Type options.
  • To set the authentication parameters for a request, enter the value of the token in the params, header, body or URL.
  • Create a path that would update the tokens specified as the authentication attributes.
  • Select the pathname in the Input Path field.
  • The selected path in the Input Path field is executed for updating the keys specified in case of authentication failure.

Note – JSON API Node only supports API whose responses are received in 5 seconds. For using a restricted API  in Engati the following IPs need to be whitelisted at the client-side.

IP1 - 65.0.229.165 IP2 - 15.206.244.196

3. Response & Attributes

The Response Section shows you the API response when hit Send after having provided the required Request URL, Params & other settings to make a valid REST API Call. 

From the API response, if you wish to show certain messages to the users you can click on the object you want to show and an attribute will be created.

You can also add attributes with their values in the postback part also, we support the following ways – 

JS


data_name=John Adam

Attribute name created will be – grade

Attribute value stored will be – A+

4. JSON Response Structure

The JSON API plugin also lets you get interactive responses from your own backend server, provided the JSON response is in a specific format.

We currently support “Send Message”, “Send Message with options” and “Send Carousel” via the JSON API plugin.

If you want to display certain information from your back end as a Message, options and carousel you can use the below JSON reference code to write an API with specific responses.



Sample APIs – 



GET
Request






GET
Request
Body Parameters
id
required
String
ID of the cake to get






GET
Request
Body Parameters
id
required
String
ID of the cake to get




Demo bot for viewing results of the sample APIs. 



In case of issues feels free to reach out to [email protected].

Updated 19 Apr 2024
Doc contributor
Did this page help you?