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.
https://yourstore.com)System > Extensions > IntegrationsChatAgentLab Order AgentSales > OrdersSales > ShipmentsCustomers > Customer InformationGet Order Status from Magento`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}*.`;
}
https://yourstore.com with your actual store domain YOUR_MAGENTO_ACCESS_TOKEN with the token you copied earlierChatAgentLab uses built-in intent detection to decide when a function should run — based on what users say.
You control this by configuring:
orderNumber)These are defined in the Custom Function Settings section when you create the function.
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.
In your custom function setup, scroll to Trigger Patterns and add:
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.
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.”
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.