Call external APIs
Let the avatar query or update your own systems during a conversation, or call any API from a flow.
When the system you need is not in the Use an app catalog, call its API directly. There are two ways:
| Where | Use it when |
|---|---|
| The Chamar API (Call API) agent in Automations | The avatar needs data during the conversation: check an order, look up a customer, register a lead. The AI extracts the values from the conversation. |
| The Fetch or send data step in Flows | A flow needs to call a system at a fixed point, with values from previous steps. |
Before you start
- The address (URL) of the API and its method (GET, POST, PUT, PATCH, DELETE).
- The credential the API asks for, usually a token in a header. Store it as an environment variable instead of typing it in the step: Flows › Variables.
In Automations: the Call API agent
Open the automation
Go to Automations and open an automation, or create one with New Automation.
Set the trigger
Under When, describe the situation in which the call should happen, for example "the customer asks about the status of an order".
Add the agent
Under Then, add an action and, in Select one of the agents:, choose Chamar API.
Fill in the request
Enter the URL, the method, the headers and the body fields. Mark the fields the AI must collect as required.
Optional: let AI fill the form
Describe the API in Instructions for automatic generation (optional): and click Fill form with AI. Review the result before saving.
How the agent behaves:
- Values from the conversation. Body fields without a fixed value are extracted from the conversation by the AI. Fields with a fixed value are sent as they are.
- Missing data. If a required field is missing, the call is not made and the avatar asks the customer for it.
- Dynamic URL. A segment written as
:fieldNamein the URL is replaced by the value of that field, for examplehttps://api.example.com/orders/:orderNumber. - The answer. The API response is given to the avatar as context, so it can answer the customer.
In Flows: the Fetch or send data step
Add the step
In a flow, add the Fetch or send data step.
Configure the request
Choose the HTTP method, enter the URL and add Query parameters, Headers and Body as needed. To start from an existing call, use Import cURL.
Use secrets safely
Insert tokens from Global variables. The value is applied only when the flow runs and is never displayed.
Choose what happens on error
Under When an error occurs, choose Stop flow, Continue without error output or Continue with error output.
Test
- Automations: talk to the avatar in a test conversation and trigger the situation you described.
- Flows: click Run to run the flow in test mode and check the step output.
Common problems
| Symptom | What to do |
|---|---|
| The avatar keeps asking for the same data | A required field is not being found in the conversation. Improve its description or make it optional. |
401 or 403 from the API | The token is missing, expired or in the wrong header. |
| The flow stops at the step | The API answered with an error (4xx or 5xx). Check the output, or choose Continue with error output and handle the error in another step. |
| Timeout | The API took too long. Raise the timeout under Options or check the API. |
AdvancedTechnical details
Fetch or send data step:
- Methods: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS. The body is ignored on GET and HEAD.
- Output:
{ "status": 200, "headers": { ... }, "body": { ... } }. Read it in the next steps as{{ $json.body }}. - A response with status 400 or higher is an error of the step and follows the When an error occurs setting. With Continue with error output, the error branch receives
status,headersandbodytoo. - 3xx is not an error. It only reaches the step when Follow redirects is off.
Chamar API agent:
- If the URL has no scheme,
https://is added. - With query parameters on, body fields not used in the URL are sent as query string.
- With the 24-hour cache on, a successful result is kept for the same URL and input. If the API fails later, the avatar uses that last good result instead.
- Context values such as the conversation, lead, avatar or open ticket ID can be added to the call by the system.
Related
- Use an app
- Receive data by webhook: the opposite direction, when another system calls Tolky.
- Tolky API