How to Integrate Shopify for Order Tracking via AI Agent in ChatAgentLab

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

  1. Go to your Shopify Admin Panel.
  2. Select Apps from the menu, then choose App development.
  3. Click on Create an app or select an existing app.
  4. Name your app (e.g., "AI Order Tracking").
  5. Under Configuration, click Edit on Admin API access scopes.
  6. Enable the following scopes:
    • read_orders
    • read_shipping
    • read_fulfillments
    • read_customers
  7. Click Save.

Step 2: Obtain the Admin API Access Token

  1. Go to the API credentials tab of your app.
  2. If the app is not yet installed, click Install App.
  3. Copy the Admin API access token (it starts with shpat_...).
  4. Keep this token in a secure location for future use.

Step 3: Create the Custom Function in ChatAgentLab

  1. Log into your ChatAgentLab account.
  2. Navigate to the AI Agent section and click on the Functions tab.
  3. Click + Add Function to create a new function.
  4. 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

Step 4: Add Authentication Headers

  1. Click + Add Header.
  2. In the Header Name field, enter X-Shopify-Access-Token.
  3. Paste your API access token from Step 2 as the Header Value.

Step 5: Configure Static Parameters

  1. Click + Add Parameter.
  2. 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

  1. Click Test Function.
  2. Input a test email associated with a recent order to verify the response.
  3. 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:

  1. Ask for the user’s email address when they inquire about tracking.
  2. Call the get_tracking_by_email() function with the provided email address.
  3. 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).