JSON API block

The JSON API block integrates the chatbot with your external applications and databases through RESTful APIs.

To add a JSON API block into a dialogue flow, click on the blue chatbot button and select JSON API.

API request setup

Under the HTTP method, select one of the following methods:

  • GET - Retrieve information about the REST API resource
  • POST - Create a REST API resource
  • PUT - Update a REST API resource
  • DELETE - Delete a REST API resource or related component
  • PATCH - Make a partial update to a REST API resource
  • HEAD - Same as GET, except without the response body
  • OPTIONS - Return available HTTP methods and other options

Under the URL, enter in the endpoint URL.

🚧

Requirement

The JSON API block only supports hypertext transfer protocol secure (HTTPS) endpoints.

Under the Header, enter the HTTP header that is being used for the request.

📘

Note

The Payload (JSON) body will only appear after selecting the POST, PUT or PATCH methods.

Using variables

If you need to use the variables from a survey block , JSON API block, or modify variable block in the URL or Header, please use the curly bracket syntax {} to represent the variables. For example: {user_id}.

📘

Note

You can directly use the access_token variable in the Header without creating a Key and Value if you tick the Add access token in Bearer option.

Example: the chatbot received a response from a JSON API block and the Result variable is set as access_token. You can directly use the access_token in the next JSON API block Header by ticking the "Add access token in Bearer" option.

You can also use the variables in the Payload (JSON) field, however these variables do not require the curly bracket syntax.

If you use a variable from a survey block please use:

  • variable.text - to represent the string value
  • variable.norm.text - to represent an integer or float value (only if the Type is set as Number)

If you use a variable from a modify variable block, just directly define the variable in the Payload (JSON).

Provide a variable name in the Result variable field to save the response values.

Click Save once complete.

View response results in other blocks

To view the response result in other blocks in the AICX platform, use the Result variable with the curly bracket syntax {}.

For example: send a POST request to retrieve a customer profile with info collected from the survey block. The response will return a JSON data object as follows:

If Result variable is defined as result, then the curly brackets syntax can be used to access {result.phone} and {result.email} value in other blocks.

Reviewing API responses

To view all Success or Failed JSON API requests, go to [History] and select [Webhooks] from the filter.