How to Integrate Shopify for Order Tracking via AI Agent in ChatAgentLab
In this guide, we will walk you through the process of setting up a custom function in ChatAgentLab that enables your AI agent to retrieve and respond with order tracking details based on a customer's email address.
Example Use Case:
User: Where is my order?
Bot: Could you please provide your email address?
User: name@email.com
Bot: Your order for "product-name" has been processed and shipped via USPS. You can track it using the tracking number 920019030243561811486929 here.
Step 1: Set Up a Private App in Shopify
- Go to your Shopify Admin Panel.
- Select Apps from the menu, then choose App development.
- Click on Create an app or select an existing app.
- Name your app (e.g., "AI Order Tracking").
- Under Configuration, click Edit on Admin API access scopes.
- Enable the following scopes:
read_orders
read_shipping
read_fulfillments
read_customers
- Click Save.
Step 2: Obtain the Admin API Access Token
- Go to the API credentials tab of your app.
- If the app is not yet installed, click Install App.
- Copy the Admin API access token (it starts with
shpat_...).
- Keep this token in a secure location for future use.
Step 3: Create the Custom Function in ChatAgentLab
- Log into your ChatAgentLab account.
- Navigate to the AI Agent section and click on the Functions tab.
- Click + Add Function to create a new function.
- Fill in the following details:
- Function Alias:
get_tracking_by_email
- Description: Retrieve order tracking details from Shopify.
- Function URL:
https://<your-store>.myshopify.com/admin/api/2023-04/orders.json
(Replace <your-store> with your actual Shopify subdomain)
- Method:
GET
- Add Parameter:
- Name:
email
- Type:
String
- Description: User's email address
- Required:
β
Yes
- Click + Add Header.
- In the Header Name field, enter
X-Shopify-Access-Token.
- Paste your API access token from Step 2 as the Header Value.
- Click + Add Parameter.
- Add the following:
- Name:
status
- Value:
any
This ensures that all orders, regardless of fulfillment status, are included in the API response.
Step 6: Set Up the Prompt Instruction
In the Prompt Instructions field, add the following instructions:
- When a user requests to track their order, ask them for their email address.
- Once you have the user's email, call the `get_tracking_by_email()` function to retrieve tracking details.```
Step 7: Test the Function
- Click Test Function.
- Input a test email associated with a recent order to verify the response.
- If successful, the response will include order details like:
- Customer name
- Fulfillment status
- Tracking number
- Shipping carrier
AI Agent Response Handling
Ensure your AI agentβs system prompt is configured to:
- Ask for the userβs email address when they inquire about tracking.
- Call the
get_tracking_by_email() function with the provided email address.
- Return the order details in a user-friendly format.
Example Response:
Your order for "Nike Sneakers" has been fulfilled and shipped via FedEx. The tracking number is 654646465465. You can track your order [here](https://www.fedex.com/fedextrack/?trknbr=654646465465).