Shopify, MySQL and Klaviyo: Repeat-Buyer Segment Template

Build a nightly Spojit workflow that counts each customer's Shopify orders in MySQL and syncs your repeat buyers into a dedicated Klaviyo segment for loyalty emails.

What It Builds

A Schedule trigger runs every night and pulls recent orders from your shopify connector. A MySQL connector node tallies how many orders each customer has placed, a Condition node keeps only the repeat buyers (those above your order threshold), and a Loop node adds each matching profile to a dedicated list with your klaviyo connector. The result is a continuously refreshed repeat-buyer audience you can target with loyalty campaigns, all running on autopilot inside Spojit.

The Prompt

Paste this into Miraxa, the intelligent layer across your automation, and it builds the workflow, connecting the tools for you:

Build a workflow that runs nightly on a schedule. Pull recent Shopify orders, then use MySQL to count how many orders each customer has placed and store the running total per customer email. For every customer whose lifetime order count is 2 or more, add their email to a Klaviyo list called Repeat Buyers so they can receive loyalty emails. Skip customers already in the list.

Connectors Used

  • Schedule trigger - runs the workflow nightly on a 5-field cron with your IANA timezone.
  • shopify - reads recent orders and customer details (list-orders, get-customer).
  • mysql - upserts and counts orders per customer (execute-query, insert-rows, update-rows).
  • klaviyo - adds qualifying profiles to your loyalty list (add-profiles-to-list, list-lists).

Customize It

Change 2 or more to a higher count for a stricter VIP tier, swap the list name Repeat Buyers for your own segment, or adjust the schedule (for example 0 2 * * * at 2am) so it runs during quiet hours. You can also restrict the order window in the prompt (last 30 days, current quarter) to control how far back MySQL counts.

Tips

  • Use Direct mode on the klaviyo and mysql nodes so each call is deterministic and costs no AI credits. Reserve Agent mode for steps that need judgement.
  • Keep a unique key on customer email in your MySQL table so re-runs update the same row instead of duplicating counts.
  • Open a small test run with a short order window first, then widen the schedule once the counts look right in your execution logs.

Common Pitfalls

  • Shopify list-orders is paginated, so a busy store may need a loop over pages to avoid missing orders in a single nightly pass.
  • Timezones matter: set the same IANA zone on the Schedule trigger that your store reports in, or "nightly" totals can straddle two calendar days.
  • Adding a profile to a Klaviyo list is idempotent, but counting is not, so make MySQL the source of truth for order totals rather than re-deriving them from each run.

Related

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.