🛠️ Handling API Status Codes in Bot Actions

While APIs aim to return correct responses, they can sometimes fail or provide unexpected responses. Monitoring the returned status code is crucial for implementing specific bot actions based on the outcome.

Accessing the Status Code

When creating an API connection within a bot action, an output field named _status_code is automatically available for each connection.

  • No need to define _status_code in the Data Link; it’s generated automatically.
  • If you assign a variable name to this output (e.g., some_variable), the status code becomes accessible via this variable in the context.

📸 Assigning Variable


Understanding Variable Type

  • Without loops: The status_code is stored as an integer.
  • With loops: The status_code becomes a list of integers.

Using Status Codes for Dynamic Responses

Once a variable is assigned to the status_code output, it can be referenced in Jinja expressions to customize responses based on its value.

Examples

  1. Display the Status Code in a Response:

    • You can print the value of the status code directly to inform users of the result.
  2. Display Status Code

  3. Dynamic Responses Based on Status Code:

    • Use conditions to customize the response based on the status code.

  1. Case Statements:
  • Directly evaluate the status_code in a case statement to trigger relevant responses or error handling routines.

This setup allows the bot to gracefully handle various API outcomes, ensuring users receive informative and context-appropriate responses.