AI REST API Connector

    Connect the bot to any backend system

    Custom tools let the AI agent call your backend during a live conversation, so answers come from real data instead of static content only: order status from an ERP, delivery tracking, support tickets, appointment availability, account data or CRM updates.

    Credentials

    The secret and configuration values needed to reach your backend, stored separately from the code so nothing is hardcoded.

    • API key, bearer token or username and password
    • Base API URL, tenant ID, company ID
    • Read in function code as credentials[:ERP_BASE_URL]
    • Use credentials for anything that differs per customer or environment

    Functions

    One function is one backend action the bot can perform: a small API operation it calls when needed.

    • Name: technical name in snake_case, e.g. get_order_delivery_status
    • Description: tells the AI when the function should be used
    • Parameters: the data needed from the customer or conversation
    • Code: the logic that calls your API, returning structured data

    Roles and intents

    A role tells the bot when a function is relevant in a conversation, and how to answer after calling it.

    • Description: what the customer is asking about
    • Instructions: which details to collect and how to answer
    • Examples: real customer phrasings that trigger the role
    • Without a role, the bot may never call your function

    How the pieces work together

    1. 1
      Customer asks

      "Where is my order 100391?"

    2. 2
      Role match

      The bot recognizes the Order delivery status intent.

    3. 3
      Missing data

      If the email is missing, the bot asks for the address used for the order.

    4. 4
      Function call

      The bot calls get_order_delivery_status with order_id and email.

    5. 5
      Live backend data

      Your ERP is called with the stored credentials and returns live order and delivery data.

    6. 6
      Natural answer

      "Your order 100391 has shipped and is in transit with DHL. Tracking ID JD014600009876543210, estimated delivery August 8."

    Setup example: ERP order status tool

    An online shop connects the bot to an ERP that holds customer orders and delivery data.

    1. Create the custom tool

    Give it a name such as ERP Order Lookup and a description like "Looks up customer order and delivery status from the ERP system." The tool groups all related functions.

    2. Add credentials

    Store the connection values as keys. They stay server side and are never exposed in the conversation.

    ERP_BASE_URL = https://erp.example-shop.com
    ERP_API_KEY  = your-api-key

    3. Add the function

    Define the name, a description that explains when to use it, and the parameter schema the AI must fill.

    {
      "type": "object",
      "properties": {
        "order_id": { "type": "string", "description": "The customer's order number" },
        "email":    { "type": "string", "description": "The email used for the order" }
      },
      "required": ["order_id", "email"]
    }

    4. Write the function code

    Read credentials and arguments, call your API, then return a structured success response with formatting guidelines for the answer.

    base_url = credentials[:ERP_BASE_URL]
    api_key  = credentials[:ERP_API_KEY]
    
    order_id = arguments[:order_id].to_s.strip
    email    = arguments[:email].to_s.strip
    
    if base_url.blank? || api_key.blank?
      failure_response("ERP credentials are missing")
    elsif order_id.blank? || email.blank?
      failure_response("Order number and email are required")
    else
      endpoint = "#{base_url}/api/orders/status"
      headers  = { "Authorization" => "Bearer #{api_key}", "Content-Type" => "application/json" }
      params   = { "order_id" => order_id, "email" => email }
    
      response = make_api_call(endpoint, params, :get, headers, false)
    
      if api_call_succeeded?(response)
        order = response[:result]
        success_response({
          "order_id" => order_id,
          "status" => order["status"],
          "delivery_status" => order["delivery_status"],
          "carrier" => order["carrier"],
          "tracking_id" => order["tracking_id"],
          "tracking_url" => order["tracking_url"],
          "estimated_delivery_date" => order["estimated_delivery_date"],
          "formatting_guidelines" => "Answer briefly. Mention order status, delivery status, carrier, tracking ID and estimated delivery date if available. Do not expose internal ERP fields."
        })
      else
        response
      end
    end

    5. Add the role or intent

    Connect customer language to the function, then select get_order_delivery_status for this role.

    Name: Order delivery status
    Description: Customer asks where their order is, whether it shipped,
    when it arrives, or asks for tracking information.
    Instructions: Ask for the order number and email if missing. Use the ERP
    order lookup function. Give the delivery status concisely and include the
    tracking ID and link when available. If the order is not found, ask the
    customer to check the order number and email.
    Examples:
      Where is my order 100391?
      Has my package shipped yet?
      Can I get the tracking number for my order?
      When will my order arrive?

    Security notes

    • The backend must verify that the order belongs to the provided email address. Never return order details based on an order number alone.
    • Do not expose internal fields, raw API errors, credentials, customer IDs or unnecessary personal data to the customer.
    • Write clear function descriptions and role instructions: most tool failures come from the bot not knowing when to call the function.

    Ask more from LastBot support

    Send us your question and our team will get back to you.