Shopify
Analyze a bounded sample of Shopify orders for sales and product bundles.
Enable Agno agents with Shopify tools to:
- Analyze sales data and identify top-selling products
- Find products that are frequently bought together
- Generate sales reports and trends
Prerequisites
- Export your Shopify shop name:
export SHOPIFY_SHOP_NAME=your_shop_name. - Export your Shopify access token:
export SHOPIFY_ACCESS_TOKEN=your_access_token. - Export your OpenAI API key:
export OPENAI_API_KEY=your_openai_key. - Grant the access token the
read_orders,read_products,read_customers, andread_analyticsAdmin API scopes.
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.shopify import ShopifyTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
sales_agent = Agent(
name="Sales Analyst",
model=OpenAIChat(id="gpt-4o"),
tools=[ShopifyTools()],
instructions=[
"You are a sales analyst for an e-commerce store using Shopify.",
"Help the user understand their sales performance, product trends, and customer behavior.",
"When analyzing data:",
"1. Start by getting the relevant data using the available tools",
"2. Summarize key insights in a clear, actionable format",
"3. Highlight notable patterns or concerns",
"4. Suggest next steps when appropriate",
"Always present numbers clearly and use comparisons to add context.",
"If you need to get information about the store, like currency, call the `get_shop_info` tool.",
],
add_datetime_to_context=True,
markdown=True,
)
# Example usage
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# Example 1: Get top selling products
sales_agent.print_response(
"What are my top 5 selling products in the last 30 days? "
"Show me quantity sold and revenue for each.",
)
# Example 2: Products bought together
sales_agent.print_response(
"Which products are frequently bought together? "
"I want to create product bundles for my store."
)
# Example 3: Sales trends
sales_agent.print_response(
"How are my sales trending compared over the last 3 months? "
"Are we up or down in terms of revenue and order count?"
)Scope the sales analysis
Set SHOPIFY_SHOP_NAME to the store prefix, such as my-store from my-store.myshopify.com, and use an Admin API access token for that shop. The three-month prompt also needs access to orders older than 60 days, including approved read_all_orders access. Otherwise, choose periods within the accessible window.
The sales tools fetch at most 250 paid orders and 100 line items per order without pagination. Their totals describe that fetched subset. Top-product revenue multiplies original unit prices by quantities, so it is not net revenue after discounts and refunds. These outputs cannot establish a complete store sales report when more data exists.
In the saved example, use this tool list:
ShopifyTools(include_tools=[
"get_shop_info",
"get_top_selling_products",
"get_products_bought_together",
"get_sales_by_date_range",
])Replace the final prompt with a request to call get_sales_by_date_range for two explicit, non-overlapping date ranges and compare the returned samples. Its date bounds are inclusive. The current get_sales_trends implementation leaves a gap between its comparison periods. The optional get_low_stock_products method also sends malformed GraphQL, so it is excluded from this example's tool list.
Run the Example
# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno
git checkout d703c34f3abf3c41275d3fb2da6e0518a8881f24
# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate
uv pip install -U openai
python cookbook/91_tools/shopify_tools.pyFor details, see Shopify tools cookbook.