All jobs

Find the Klaviyo Coupons About to Run Out of Unique Codes Before Your Flows Do

An online skincare store's agent counts each Klaviyo coupon's unassigned codes weekly and says which run out before next week's welcome and win-back emails.

Run this on RushOpens the console with this prompt ready to send. Connect Klaviyo there first.

What the agent does

This is for an online skincare store whose email runs on Klaviyo. Its welcome series gives every new subscriber a unique discount code, its win-back flow gives lapsed customers another, and a birthday flow a third. Each of those is a Klaviyo coupon with a pool of unique codes the store uploaded, and each email takes one code from the pool. The store does not want to learn that a pool is empty from a customer whose welcome email has no working code, so the agent checks the pools every Monday. It signs in to Klaviyo's remote MCP server at https://mcp.klaviyo.com/mcp, which Rush lists as a connector that signs in with OAuth. Connect it once with the API key: POST /me/connections {"type": "mcp", "name": "klaviyo", "url": "https://mcp.klaviyo.com/mcp", "auth": {"mode": "oauth"}} answers 202 with an authorize_url, which the key's creator opens while signed in to the Rush console.

The agent calls get_coupons to list the store's coupons. For each coupon it calls get_coupon_codes with a filter on that coupon.id and status equal to UNASSIGNED, which Klaviyo requires: the endpoint refuses a request that names neither a coupon nor a profile. It pages 100 codes at a time, Klaviyo's maximum, and counts them. A second filter, status UNASSIGNED with expires_at less than four weeks from today, finds codes that will expire before anyone receives them, which do not count as stock.

To turn a count into weeks, the agent needs how fast each pool is used. Klaviyo does not record when a code was handed out, so the store's prompt names which flow draws from which coupon, and the agent calls get_flow_report for each of those flows with the recipients statistic over last_7_days. The report needs a conversion metric, so the agent uses the store's Placed Order metric. Weeks left is the usable unassigned codes divided by last week's recipients. A coupon below four weeks goes to the top of the report.

The agent only reads. Klaviyo's tool list marks create_coupon_code, bulk_create_coupon_codes, update_coupon_code and the delete tools as writes, and the prompt forbids them: new codes come from wherever the store generates its discounts, and someone has to make them valid at checkout before they go into Klaviyo. The job also reads no profiles or events, the tools Klaviyo's documentation warns can return customer-written text.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Weekly Klaviyo coupon stock check. Today is 2026-11-23. Flows and the coupon each uses: Welcome Series uses WELCOME15; Win-back uses COMEBACK20; Birthday uses BDAY10. 1) get_coupons. 2) For each coupon, get_coupon_codes filtered by coupon.id and status UNASSIGNED, page size 100, count all pages; then count UNASSIGNED codes with expires_at before 2026-12-21. 3) For each flow above, get_flow_report with statistics recipients and timeframe last_7_days, using the Placed Order metric as the conversion metric. Return a Markdown table sorted by weeks_left: coupon, unassigned, expiring_before_use, usable, flow, recipients_last_7_days, weeks_left. Then one line per coupon under 4 weeks saying how many codes cover 8 weeks. List any coupon with no flow mapped. Read only: never call a create, update, delete or bulk tool, and do not read profiles or events.",
  "connections": [
    "klaviyo"
  ]
}
  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

The answer is one table, lowest stock first: each coupon, how many unassigned codes it has, how many of those expire before they would be used, the flow that draws from it, how many people that flow reached last week, and the weeks of codes left at that rate. Under it, a line for each coupon below four weeks with how many codes would cover eight, and a list of coupons the prompt did not map to a flow, so a coupon used by a new flow does not go unwatched.

The marketer checks two things before acting. Last week's recipients are an estimate of next week's: a sale, a big signup week or a paused flow changes the rate, so a pool just above four weeks before Black Friday is treated as short. And a coupon whose codes all show VERSION_NOT_ACTIVE or PROCESSING rather than UNASSIGNED is looked at in Klaviyo before anyone generates more codes for it.

Run it on every Monday morning

Save the prompt as an agent with POST /o/{org}/agents and connections: ["klaviyo"], and give it an automation in the console with a schedule trigger, a cron such as 0 7 * * 1 and the store's timezone, so the table is ready before the week's planning; a schedule fills nothing into the prompt, so the saved prompt says "today" and "28 days from today" in place of the dates. Automations need Pro or Max. When the store adds a flow that hands out codes, it edits the agent's prompt once with PATCH /o/{org}/agents/{id}.

Before a sale, run it on demand with the sale's expected volume in the prompt in place of last week's recipients, and the table answers how many codes to generate for the sale itself.

The use case this job follows, with its automation and trigger: Produce a report or file, no repo.

Why run it on Rush?

Klaviyo shows a coupon's codes one coupon at a time, and its API requires a coupon or profile filter on every code read, so a script means paging each pool, joining it to flow reports, and keeping a private API key with coupon and reporting scopes on a server. On Rush the Klaviyo sign-in stays in Rush's connection, and the agent does the paging and the arithmetic in its own computer.

Each Monday's check is a session with a record of every Klaviyo call and its answer, so when a customer writes in about a blank code, the store can open the last few weeks' runs and see when that pool started falling, alongside what each check cost.

Frequently asked questions

Why does the prompt have to say which flow uses which coupon?

The coupon code read returns each code's unique_code, expires_at and status, and nothing about which flow assigned it or when. Naming the pairs in the prompt is the simplest way to get a usage rate. Without them, the agent can still report how many codes each coupon has left.

What do the code statuses mean for stock?

Klaviyo lists UNASSIGNED, PROCESSING, ASSIGNED_TO_PROFILE, VERSION_NOT_ACTIVE, DELETING and USED. Only UNASSIGNED codes are left to hand out, so that is what the agent counts, after removing the ones that expire too soon.

Will this hit Klaviyo's rate limits on a big pool?

Klaviyo's reference gives the coupon codes read a burst of 350 a second and a steady 3,500 a minute at 100 codes a page, so even a pool of tens of thousands of codes is a few hundred calls. The agent pages one coupon at a time.

Can it upload the new codes when a pool is low?

Klaviyo has bulk_create_coupon_codes, but this prompt forbids it. The codes must exist and work at checkout before Klaviyo hands them out, so the person who creates them in the store's platform also adds them to Klaviyo.

More Klaviyo jobs

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

Keep reading