Skip to main content

Use the call api node in chatbot

You can use the “Call API” to call an api from the chatbot itself. You can even use the response of the API in the chatbot flow.

Configuration

  • API - You can select or configure the api details from the API section

    • Click on "Show Editor" update the API configuration
    • If you are using a json payload, you can type {{ to show a list of available variable substitutions
    • You will have access to the last chat message text and the data collected via the chatbot API Editor
  • Store response in variable? - Provide a variable name to store the api response in a variable

  • JSON path of value to store? - Provide a json path to extract a certain specifc value from the JSON response and store in the variable

    1. The api response is accessed with the key response.data
    2. so if your api response is { "value": "this is the response" }
    3. then the jsonpath should be response.data.value

Call API Node Configuration

Output

The API will either result in a success (2xx response) or a failure (non 2xx response). You can link the options to furtherr nodes accordingly.

Call API Node output

Guide

Below is a step by step guide to building a new chatbot with “Call API Node”

  1. Create new chatbot from https://app.chakrahq.com/admin/chatbot-settings#chatbots
  2. Edit the welcome node and provide a welcome message like “Welcome”
  3. Click Save to close the welcome node editor
  4. Drag and drop a “ask a question” node to the right of the welcome node
  5. Link the welcome node to the “ask a question” node
  6. Edit the question node, and under the “Text” input add a question like “What is your query?”
  7. Under “Store in a variable” add a variable name like “query”
  8. Click Save to close the question node editor
  9. Drag and drop the “Call API” node to the right of the question node
  10. Edit the “Call Api” Node
  11. Click “Show Editor” next to the selected API
  12. Make necessary changes like providing the api url and selecting the http method
  13. Chose “form url encoded” or “form multipart” from the body type
  14. Click “Add Another” under the “key value” section
  15. A new entry will be created - under key provide the key name like “text”, Under value select the query variable
  16. Click “Save API” to close the editor
  17. Under “Store response in variable” add a variable name like api_response
  18. Under “JSON path of value to store” add a json path to select a specific value from the api response to store
    1. The api response is accessed with the key response.data
    2. so if your api response is { "value": "this is the response" }
    3. then the jsonpath should be response.data.value
  19. Click “Save" to close the api node editor
  20. Drag and drop a message node to the right of the api node
  21. Connect the Success option of the api node to the new message node
  22. Edi the message node
  23. Type in a message for the message node. If you want to access the data returned in the api node, type @ and start typing to get a menu of variables available. Choose ‘api_response’ variable
  24. Click save to save the message node
  25. Click Save from the top right corner to save the chatbot

This chatbot will ask user a question and then hit your configured api with the user response. If an api response is received then the response is sent back to the user.

Guide