← Back to danpeguine.com

How We Taught Our AI to Generate Custom Sales Reports

Shopify API, historical baselines, and automated WhatsApp delivery — from 2 hours of manual work to 5 minutes of review.


The Problem

Every Sunday morning, someone in our family's tea business has to build the weekly sales report for management. It sounds like a simple task until you actually sit down to do it.

The process: pull sales data from Shopify, break it down by channel — two retail stores, Uber Eats, web orders, and B2B restaurant clients. Calculate revenue, ticket counts, and average basket size for each. Then compare everything to the same week last year. Format it nicely. Send it to the management group chat.

Two hours of clicking, exporting, and Excel formulas. Every single week.

We wanted to see if our OpenClaw agent (CamelliaOS) could learn to do this.


Step 1: Understanding the Existing Process

Before automating anything, Camellia needed to understand what the report actually looked like. We walked it through the manual workflow — the Shopify exports, the Excel formulas, the final format that goes to the group chat.

The existing manual sales reporting process
The manual process: exporting from Shopify, breaking down by channel, formatting in Excel
Excel spreadsheet with manual sales calculations
The weekly report that took 2 hours of manual work to produce

Step 2: API Access — Harder Than Expected

The first real challenge wasn't the report logic — it was getting access to the data. Camellia tried to connect to Shopify's API, but immediately hit a wall.

Shopify had deprecated "Custom Apps" — the approach that most online tutorials still recommend. Every guide was outdated. Camellia had to figure out the new OAuth flow from scratch, navigating Shopify's current documentation rather than relying on old patterns.

Shopify OAuth configuration and API setup
Navigating Shopify's new OAuth flow — old tutorials didn't work

The hard-won knowledge was saved to docs/SHOPIFY-OAUTH.md so we'd never have to figure it out again. This is the pattern: when the agent solves something difficult, document it immediately.


Step 3: Understanding the Data

With API access working, the next challenge was classifying orders correctly. Not all sales are the same — the report needs to break them down by channel.

Data classification logic for different sales channels
Mapping order attributes to sales channels — POS IDs, customer tags, source fields

These rules aren't documented anywhere in Shopify. They're tribal knowledge — the kind of thing that lives in one person's head. Teaching them to the agent means they're now explicit and permanent.


Step 4: Historical Baseline

The report doesn't just show this week's numbers. It compares them to the same week last year. That means the agent needs historical data.

Charles had years of historical data in spreadsheets. We converted these to JSON format — data/weekly_baseline.json — so Camellia could calculate year-over-year deltas automatically.

Historical sales data converted to JSON format
Years of historical data, converted from spreadsheets to structured JSON

Step 5: Matching the Exact Format

The first report output was close — but "close" isn't good enough when management is used to seeing numbers in a specific format every week.

"This is close but not quite right."

What followed was several rounds of iteration. The agent added ticket counts, then an average basket section, then YTD totals. Each round got closer to matching the existing report format exactly.

First iteration of the automated report
Early iteration — the numbers were right but the format needed work
Refined report matching the expected format
After several rounds of feedback, the format matched expectations

Testing and QA

We ran the automated report side-by-side with Charles's manual version. Week 3 — compared and validated. Week 4 — numbers matched. The agent also generated PNG visualizations for quick sharing in the group chat.

Side-by-side comparison of automated vs manual report
Side-by-side validation: automated output vs. manual report
"Looks good, but can you add percentage change?"

Each piece of feedback was incorporated and saved permanently into the skill definition. The report gets better over time, and corrections are never lost.


The Surprise: It Built Its Own Tool

Here's where it got interesting. Rather than running the same API calls every time, Camellia built its own reusable tool to fetch and process the Shopify data. Without being asked to.

The agent's self-created data fetching tool
Camellia built its own tool to automate the data pipeline

This is a pattern we see with well-trained agents: given a clear goal and enough context, they start optimizing their own workflow. The tool encapsulates the Shopify connection, data classification, and baseline comparison into a single callable function.


The Skill Structure

The entire reporting workflow was formalized into a skill — an SOP that the agent can execute independently. The skill includes the data-fetching tool, the formatting rules, the historical baseline, and the delivery instructions.

The skill definition file structure
The skill structure — everything the agent needs to produce the report
Skill configuration and parameters
Skill configuration with data sources, formatting rules, and delivery targets

Delivery via WhatsApp

The last piece: getting the report to where it needs to go. The report generates on the server, Camellia sends the images directly to the management group chat. No more manual export, format, screenshot, send.

Scheduled to run every Sunday morning. Management gets the report before they've finished their coffee.


The Result

What we accomplished

The pattern is the same as our scheduling case study: find a workflow that eats your time, teach the agent how you do it, formalize it into a skill, and iterate until it's right.

The agent didn't just replicate the process — it improved it. It built its own tooling, documented the hard parts, and now runs the entire workflow autonomously every week.

We used the same approach to automate employee scheduling — WhatsApp messages, French voice notes, and a lot of iteration. Read that case study →

Get the free guide that walks through this approach in detail — for you and your AI agent to read together.

Community launching soon.

@danpeguine · LinkedIn · Instagram Powered by OpenClaw