Hi, Humans. How may we help you?

05. API Call in Chatbot
4 min
Created by Maria Malheiro on 2/8/2024 4:11 PM
Updated by Ligia Sarmento on 8/26/2024 11:21 AM

In Zenvia Customer Cloud, the API Call feature allows users to include an API within their chatbot. An Application Programming Interface (API) is a way for one program to interact with another, hence API calls are the means by which they interact. Thus, it's possible to use an API call to send data to your CRM, query customer data in databases, or even send external communications.

How to Access

The API Call content is available in the Constructor and to access it, simply click on the three dots of the block or anywhere within it.

This will open the Block Details modal, then follow these instructions:

  1. Click on Add content > Conversation actions > API Call.
  2. In Method, specify the type of your API, whether it's: POST, GET, DELETE, PUT, or PATCH.
  3. Provide the URL, including a link to this API.
  4. In Header, include the respective code, editing the code will be similar to any common editor. For example, it could be Authorization, Application, etc.
  5. In Body, include the code. Remember that this will depend on the API. For example, if we have a JSON application, in the body, the code will be JSON.

💡 Tip: If the API response includes an array of objects, as in the example below, where you want to access the communication channel of the first event, the code to display this information would be:

"resposta_api": {
"body": {
"events": [
{
"extra1": null,
"extra2": null,
"channel": "widget",
"eventName": "new_dialog",
"assistantId": 142,
"environment": "dev"
}
]
},
"code": 200,
}

In this example, events[0] refers to the first object within the events array, and channel is the field you want to access and display in the chatbot conversation.