How to Integrate ChatAgentLab with Magento for Real-Time Order Tracking

This guide shows you how to connect your Magento webshop to ChatAgentLab so your AI agent can automatically answer questions like “Where is my order?” or “Has my delivery shipped yet?”

With this setup, your AI agent will detect tracking-related queries, fetch real-time order status from Magento using API, and respond intelligently to customers — all without human involvement.


✅ What You'll Need

  • A ChatAgentLab account
  • Access to your Magento Admin Panel
  • A Magento API access token
  • Your website’s base URL (e.g., https://yourstore.com)

🔐 Step 1: Enable Magento API Access

  1. Log into your Magento Admin Panel
  2. Go to System > Extensions > Integrations
  3. Click Add New Integration
  4. Set:
    • Name: ChatAgentLab Order Agent
    • Email: leave blank or use your own
  5. Under API, allow the following read-only permissions:
    • Sales > Orders
    • Sales > Shipments
    • Customers > Customer Information
  6. Save and Activate the integration
  7. Copy the generated Access Token — you’ll need this in the next step.

⚙️ Step 2: Create a Custom Function in ChatAgentLab

  1. Log into ChatAgentLab
  2. Select your AI Agent > go to Functions Lab > click Add Custom Function
  3. Name it: Get Order Status from Magento
  4. Paste this sample code:

`javascript
async function getOrderStatus(orderNumber) {
  const response = await fetch(`https://yourstore.com/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=increment_id&searchCriteria[filter_groups][0][filters][0][value]=${orderNumber}`, {
    method: 'GET',
    headers: {
      'Authorization': 'Bearer YOUR_MAGENTO_ACCESS_TOKEN',
      'Content-Type': 'application/json'
    }
  });

  const data = await response.json();
  const order = data.items?.[0];

  if (!order) {
    return "Sorry, I couldn't find any order with that number. Please double-check and try again.";
  }

  return `Ordre #${order.increment_id} now has status: *${order.status}*.`;
}

🛑 Important

  • Replace https://yourstore.com with your actual store domain
  • Replace YOUR_MAGENTO_ACCESS_TOKEN with the token you copied earlier

🧠 Step 3: Define When the AI Should Trigger the Function

ChatAgentLab uses built-in intent detection to decide when a function should run — based on what users say.

You control this by configuring:

  • Trigger phrases (e.g., “Where is my order?”, “Track my package”, “Order status”)
  • Input variables (e.g., orderNumber)

These are defined in the Custom Function Settings section when you create the function.


🧩 How it works

Your AI agent listens for messages that match specific patterns, like:

“Where is my order [order number]?”
or
“Track order [number]”

If no order number is provided, ChatAgentLab will ask a follow-up question like:

“Sure! Could you give me your order number?”

Once the order number is identified, the AI automatically runs the custom function and fetches real-time data from Magento.


🧰 Configure in ChatAgentLab

In your custom function setup, scroll to Trigger Patterns and add:

  • “Where is my order?”
  • “Track my package”
  • “What’s the status of order 12345?”

Then scroll to Required Variables and add:

json
{
  "required_variables": ["orderNumber"]
}

This ensures the AI responds naturally when the user is asking about delivery — and knows when to activate the Magento function instead of just chatting normally.


🧪 Step 4: Test the AI Agent

Try typing to your AI agent:

“Can you check order 100456?”

If everything is connected correctly, the bot will respond:

“Order #100456 now has status: Sent.”


💡 Bonus: Translate Status Codes

Magento uses system statuses like pending, processing, and complete. You can translate these into user-friendly messages like this:


const statusMap = {
  "pending": "waiting to be processed",
  "processing": "in process now",
  "complete": "completed and sent"
};

return `Ordre #${order.increment_id} har nå status: *${statusMap[order.status] || order.status}*.`;

## 🆘 Need Help?

ChatAgentLab offers onboarding help and live chat support if you want help connecting your Magento store or optimizing your function logic.