# Which Customers Are Due to Reorder? A Coffee Roaster's Weekly List From Its Neon Orders Database

An online coffee roaster's agent queries its Neon orders database every Monday and lists repeat customers who are past their usual time between orders.

[Run this on Rush](https://cloud.getrush.ai/run/find-customers-due-to-reorder/neon/). Opens the console with this prompt ready to send. Connect Neon there first.

## What the agent does

This is for a small coffee roaster that sells beans online from its own shop, with orders stored in a Postgres database on Neon: `customers`, `orders`, `order_items` and `subscriptions`. Most revenue comes from people who buy the same bag every few weeks without subscribing. Each of them has a rhythm, one every three weeks, another every six, and when someone misses theirs by a week they have often found another roaster. The owner wants a list each Monday of repeat customers who are late, with what they usually buy, to send a short note from the shop's email tool.

The owner connects Neon once with `POST /me/connections {"type": "mcp", "name": "neon", "url": "https://mcp.neon.tech/mcp", "auth": {"mode": "oauth"}}` and opens the `authorize_url`. Neon's docs say an OAuth sign-in can choose read-only scope on its own page, which leaves `SELECT` queries and schema inspection and disables writes, and withholds connection strings. The owner chooses read-only, so no query this agent writes can change an order. The request names `neon` in `connections`.

On a run the agent first reads the columns it relies on from `information_schema.columns` with `run_sql`, and stops with a clear message if one is missing, rather than guessing a name. Then it runs a few `SELECT` statements. For each customer with at least three paid orders, it computes the median number of days between orders and the date of the last one; it keeps customers whose days since the last order exceed that median by seven or more, and drops anyone whose last order is more than 90 days old, since they are lapsed rather than late. It leaves out customers with an active row in `subscriptions` and customers whose `marketing_opt_in` is false.

Neon's docs say `run_sql` returns up to 100 rows per statement by default, so the agent pages through the result with `LIMIT` and `OFFSET` ordered by customer id until a page comes back short. For each late customer it reads the product they bought most often from `order_items`. It writes `reorder.csv` with customer id, first name, email, usual product, usual interval, days since last order and days late, sorted by days late, and `reorder.md` with counts by product. The roaster's email tool sends the notes; the agent sends nothing.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Find repeat customers who are late to reorder, as of 2026-11-23. Use the neon connection, project roastery-shop, database neondb, read only. First run_sql on information_schema.columns to confirm: customers(id, first_name, email, marketing_opt_in), orders(id, customer_id, status, created_at), order_items(order_id, product_name, quantity), subscriptions(customer_id, status). If any is missing, stop and list what is missing. Using only SELECT: for customers with at least 3 orders with status 'paid', compute the median days between consecutive paid orders and the last paid order date. Keep customers where days since last order >= median + 7 and last order within 90 days. Exclude customers with a subscriptions row where status = 'active', and customers where marketing_opt_in is false. Page every query with ORDER BY customer id, LIMIT 100 and OFFSET until a page returns fewer than 100 rows. For each kept customer, find their most-ordered product_name by total quantity. Write reorder.csv (customer_id, first_name, email, usual_product, median_days, days_since_last, days_late) sorted by days_late descending, and reorder.md with the count by usual_product. Never run INSERT, UPDATE, DELETE or DDL.",
  "connections": [
    "neon"
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

`reorder.csv` and `reorder.md` list the customers due to reorder this week. The session returns both as artifacts. The owner imports the CSV into the shop's email tool as this week's reorder list and writes the note once, perhaps with a word about the new harvest of a customer's usual bean. The transcript shows every SQL statement the agent ran, so if a name on the list looks wrong, the owner can read exactly how it got there.

What the owner checks: customers who reordered by phone or at a market stall and never went through the website, who will look late here; anyone who asked not to be contacted by a route the database does not record; and customers with exactly three orders, whose median rests on two gaps and is a rough guide. The agent applies the rules in the prompt and invents none of its own.

## Run it on every Monday morning

In the console, a Project automation with a `schedule` trigger at `0 7 * * 1` in the roaster's `timezone` runs a saved agent whose connections name `neon`, with this prompt and "as of today" in place of the date. A schedule fills nothing into the prompt, so the agent writes the date it used at the top of `reorder.md`.

Each Monday is its own session, so the roaster keeps a dated list of who was due and can compare it with who actually reordered the week after, which is the only honest way to tell whether the notes help.

## Why run it on Rush?

The query needs access to the shop's live customer data, and that access should not be a database password copied into a spreadsheet macro. On Rush it is a read-only Neon sign-in in the owner's connection, chosen on Neon's own page, and each run reads with it and cannot write.

Each run has its own computer and a record of every statement and what its model calls cost, so the weekly list has a known cost beside the sales it is meant to bring back. A fixed SQL script would compute the same median, but the agent also checks the schema first, says plainly when a column is renamed after a shop update, and writes the summary the owner actually reads.

## Frequently asked questions

### Can the agent change or delete orders?

Not with a read-only sign-in. Neon's docs say read-only mode keeps `SELECT` and schema inspection and disables writes, and the prompt forbids anything but `SELECT` as well. The transcript lists each statement, so the owner can confirm it.

### Our shop platform stores orders differently. Does this work?

If the orders are in a Postgres database on Neon, yes: change the table and column names in the prompt to yours. The agent checks them against `information_schema` before it computes anything and stops if they do not exist.

### Will it send the reorder emails?

No. It has no email connection in this request, and the list goes to the owner, who sends from the shop's email tool. That keeps the wording, the timing and the unsubscribe link with the tool that already handles them.

### Why drop customers whose last order is more than 90 days old?

Someone that far past their rhythm is a lapsed customer, and a reorder reminder reads oddly to them. The roaster can run a separate win-back list with its own wording, or change the 90 in the prompt.

## More Neon jobs

- [How Much Neon Did Each Client Use Last Month? A Software Agency's Usage Report for Invoices](https://getrush.ai/run/bill-each-client-for-neon-usage/neon/)
- [What Were Our Numbers Last Month? An Investor-Update App's Read-Only Metrics From Each Startup's Neon Database](https://getrush.ai/run/draft-monthly-metrics-for-investor-update/neon/)

## More jobs like this: Produce a report or file, no repo

- [Which Customers Keep Hitting Our Rate Limits? An SMS API Company's Weekly List From Axiom](https://getrush.ai/run/find-customers-hitting-rate-limits/axiom/)
- [How Do I Find Which Customers' Webhook Endpoints Keep Failing? A Weekly Report From Axiom for a SaaS Customer-Success Team](https://getrush.ai/run/find-customers-whose-webhooks-keep-failing/axiom/)
- [Find Dead Code in an Angular App](https://getrush.ai/run/find-dead-code/angular/)
- [Find Dead Code in a Next.js Project](https://getrush.ai/run/find-dead-code/nextjs/)

## Keep reading

- [Connect Neon to Rush once, then name it on any run](https://getrush.ai/integrations/neon/)
- [Start your first run from the developer API quickstart](https://getrush.ai/docs/quickstart/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
