In Zenvia Customer Cloud, the API Call feature allows you to integrate external systems with your chatbot. With it, you can:
- Retrieve customer data from a CRM.
- Send information to external systems.
- Automate actions based on dynamic data.
An API (Application Programming Interface) is the means by which different systems communicate with each other.
How to access
In the Bot Builder:
- Click the three dots on the block (or anywhere inside the block).
- Click Add content.
- Select API Call.
How to configure an API Call
Fill in the following fields:
- Method: GET, POST, PUT, DELETE, or PATCH.
- URL: API endpoint.
- Header: (e.g., Authorization, Content-Type).
- Body: according to the expected format (e.g., JSON).
Why use another block?
Blocks are executed in the following order:
- Send message;
- Receive messages;
- Save variables;
- Execute actions (including API calls);
- Define the next flow.
This means that the API response will only be available after the block finishes executing. You need a new block to use the returned data.
How to display a specific variable in the flow
The main goal is to make it easier to understand how to navigate through the JSON returned by the API and how to use values inside chatbot messages. Below are clearer, more practical examples that can replace or complement the current documentation section.
How to access a specific API variable
Every API response is available in the default variable:
<? $resposta_api.body ?>
It contains the entire JSON returned by the API call.
Example 1 — Display only the customer's name
API response
To access only the customer's name, use:
<? $resposta_api.body.cliente.nome ?>
Message in the flow block
Result shown to the user:
Hello, Carlos Silva!
Use this pattern whenever you want to display only a specific field from the API response.
Example 2 — Display more than one customer information
API response, message in the flow block, and displayed result:
Hello, Carlos Silva!
Your current plan is Premium. Registered email: [email protected].
This example shows that each JSON field can be accessed individually.
Example 3 — Display a value inside an array
API response
To access the first order, use index [0]:
<? $resposta_api.body.pedidos[0].numero ?>
To access the status of the first order:
<? $resposta_api.body.pedidos[0].status ?>
Message in the flow block
Displayed result
Your order 12345 is currently "In transit".
Use [0] for the first item in the array, [1] for the second, and so on.
Example 4 — Understanding the variable path
API response
The path to the city is:
Customer → Address → City
Therefore, the correct variable will be:
<? $resposta_api.body.cliente.endereco.cidade ?>
Message in the flow
Result:
Customer city: São Paulo
The rule is simple: follow the JSON structure using a dot (.) for objects and [n] for arrays.
Visual example of the correct flow
Recommended flow
⚠️ Important: Data returned by the API is only available after the API block has finished executing. Therefore, the data should be displayed in a subsequent block.