How to use the REST API action in chatflows?

The REST API action in chatflows allows you to integrate external services with Customerly by sending and receiving data during a chatflow.

Luca Micheli
Written by Luca MicheliLast update 29 days ago

The REST API action enables you to call any external service using data collected during the chatflow. This powerful feature allows for seamless integration and advanced functionality within your automated workflows.

Key Features of REST API Action

  • External Service Integration: Call any external service with data gathered from the chatflow.

  • Dynamic Data Usage: Use contact, company, or conversation properties in the header, URL, and body of the request.

  • Environment Variables: Add environment variables for dynamic and secure data handling.

  • Response Handling: Capture responses from the API and store values in variables using JSON dot notation.

Setting Up REST API Action

  1. HTTP Method and URL: Choose the HTTP method (e.g., GET, POST) and specify the endpoint URL.

  2. Headers: Include headers using properties like user email or company ID for authorization or content type.

  3. Body: Construct the body using JSON, form data, XML, HTML, or raw data. Incorporate variables to dynamically send relevant information.

  4. Capture Response: Extract data from the API response using JSON dot notation and store it in conversation properties.

Example 1: Capturing a Specific Value from JSON

Scenario: Extracting a user ID from an API response.

  • API Response:

{
  "status": "success",
  "data": {
    "user": {
      "id": "12345",
      "name": "John Doe"
    }
  }
}

  • Capture Response Configuration:

    • JSON Path: data.user.id

    • Store In: conversation.user_id

This setup captures the user.id from the response and stores it in the conversation.user_id property.

Example 2: Sending a Message with Context on Slack

Send a message to a Slack channel when a new sales opportunity is identified.

Configuration

  • Method: POST

  • URL: {{env.slack_hook_url}}

  • Headers:

    • Content-Type: application/json

  • Body:

{
  "text": "🚀 New Sales Opportunity\nEmail: {{user.email}}\nSeats needed: {{conversation.seats_needed}}\nCurrent Setup: {{conversation.current_setup}}"
}

In this example, the REST API action sends a message to a Slack webhook URL with context from the conversation. The message includes the user's email, the number of seats needed, and the current setup information.

Benefits of Using REST API Action

  • Advanced Integration: Connect with external systems to expand the capabilities of your chatflows.

  • Dynamic Data Handling: Use dynamic data from conversations to personalize API requests.

  • Automated Workflows: Automate complex workflows by integrating third-party services seamlessly.

The REST API action in chatflows provides a versatile and powerful way to enhance your customer interactions by integrating external services.

Whether capturing specific data from API responses or sending contextual messages to platforms like Slack, this feature enables sophisticated automation and integration to streamline your support processes.

Save a request as a template

During the creation of a chatflow you can click the save icon on the bottom and save the request as a template to reuse it later in any chatflow.

Did this answer your question?