Blog

How to build a purchase approval app with an AI agent

People ask to buy things, someone approves, and finance wants a record. What a small purchase approval app needs, how to ask a coding agent for one that gets "who asked" and "who approved" right, how the approver hears about it, and what a real approvals product does that this won't.

Most small companies approve purchases in chat. "Can I order two monitors for the new starters? About $400." A thumbs-up from the right person, and that's the approval. It works until finance asks, three months later, who approved the $2,300 software renewal, and the answer is somewhere in a thread nobody can find.

A purchase approval app is one of the first things people ask a coding agent for, and one of the easiest to get subtly wrong. This article is about building one that holds up: what it needs, what to tell the agent, and where it stops. We make Spryloom, which runs the app in the examples, so read those parts knowing who wrote them.

What the app has to get right

An approval is only worth something if three facts can be trusted:

  • Who asked. The person signed in when the request was made, not a name typed into a box.
  • Who approved, and that they were allowed to. Checked on the server, not by hiding a button.
  • When, and what exactly. The item and amount at the moment of approval.
  • Editable after approval. Then the approval means nothing.

Then there's the part that makes people use it: the approver has to hear about waiting requests without opening the app every morning to check.

The two roles

Keep it to two kinds of people. On Spryloom, every visitor arrives at the app with two headers, set by Spryloom after they sign in:

const email = request.headers['x-spryloom-email'];  // who they are
const role  = request.headers['x-spryloom-role'];   // 'admin' or 'user'

Users request. Admins approve. The person who publishes the app is an admin, and so is anyone listed in the manifest:

access:
  visibility: invited
  admins: [chris@yourcompany.com]

So Taylor, who runs operations, publishes the app and names Chris, the finance lead, as the second approver. Everyone else who's invited is a user.

Use the header, never a form field

This is the mistake to watch for. An agent building a request form will often add a "Requested by" field, because that's what forms have. Tell it not to: anyone can type anyone's name into it. The header can't be forged: Spryloom deletes any x-spryloom-* header that arrives with a request before it decides anything, so the only copy that reaches the app is Spryloom's own.

The same goes for approving. The server should check x-spryloom-role is admin before it records an approval, and record x-spryloom-email as the approver. A hidden button is a convenience. The check on the server is the rule.

Requested by: Chris typed: anyone can x-spryloom-email from sign-in: can't be forged Requested admin? Approved
Record who asked from the header, and check the approver's role on the server before an approval counts.

What to ask the agent for

Something like this, in one message:

Build a purchase approval app. Anyone invited can request a purchase: item, amount, supplier, reason. Admins can approve or reject, with a note. Take the requester and the approver from the x-spryloom-email header, never from a form field, and check the role on the server. Once a request is approved or rejected it can't be edited. Keep a people table of everyone who uses the app with their role. Every weekday at 9am New York time, email the admins how many requests are waiting.

The agent writes a small Node server with a Postgres database and declares what it stores in spryloom.yaml:

data:
  postgres: true
  tables: [requests, decisions, people]

Those table names appear on the app's label page, which every coworker can see, so they know what the app holds before they put anything in it. Confirm them with the agent before it publishes.

Keeping decisions in their own table, rather than a status column someone can overwrite, gives finance what it wants: every approval and rejection as its own row, with who and when.

Telling the approver

The approver shouldn't have to remember to look. A daily email does it, and it has two parts: a schedule and an address.

The schedule is a job, declared in the manifest rather than a timer inside the server, because the server sleeps when nobody is using it:

jobs:
  - name: approver-digest
    command: node jobs/digest.js
    schedule: "0 9 * * 1-5"
    timezone: America/New_York
email: true
  1. A job, not a timer in the server.
  2. Its name, used to run it by hand.
  3. What it runs. 10 minutes by default, 15 at most.
  4. 9:00 on weekdays. At most once every 10 hours.
  5. New York time.
  6. email: true lets it email the app's own people.

The address is the subtle part. A job runs with no visitor and so no headers: it doesn't know who the admins are. That's what the people table is for. Each time someone uses the app, the server records their email and role, and the job emails the rows whose role is admin. Taylor, as the owner, is recorded the first time Taylor opens the app, so nobody types an address into a setting.

The email is one digest, not one message per request, because an app can send at most 5 emails a day, only to people who use it. Counts in the email, details behind the button:

From Purchase approvals via Spryloom · To chris@yourcompany.com
Subject 3 purchase requests are waiting

3 requests are waiting for your approval.

Review requests

The button opens /approvals. Chris approves there, signed in.

The code that sends it:

await notify({
  to: approver.email,
  subject: '3 purchase requests are waiting',
  text: '3 requests are waiting for your approval.',
  button: { label: 'Review requests', path: '/approvals' },
  dedupeKey: `digest-${today}-${approver.id}`,
});

Keep what people typed out of the email text. A supplier written as "dell.com" would get the whole email refused, because the text can't contain anything shaped like a web address. More on how this works is in how to send a daily email reminder.

To try the job without waiting for Monday:

purchase-approvals
spry jobs run purchase-approvals approver-digest
spry logs purchase-approvals --job approver-digest
# 5 failures in a row pause it and email the owner; once fixed:
spry jobs resume purchase-approvals approver-digest

Publish and invite

From the app's folder, or by asking the agent:

npx -y spryloom publish
spry invite purchase-approvals --email sam@yourcompany.com --email jordan@yourcompany.com

The app has no login code of its own. Spryloom signs people in with an emailed link before any request reaches the app, and being let into this app grants nothing on any other.

What it doesn't do

A dedicated approvals or spend-management product does a lot this app won't, and it's worth knowing before you rely on it:

  • No receipts or quotes attached. File uploads aren't available, so the app can't store a PDF quote. Link to where it lives, or keep it in your accounting tool.
  • No connection to your accounting system. An app can reach a fixed list of outside services, and accounting and ERP systems aren't on it. Approved requests are exported from the app, not synced.
  • No approval chains out of the box. "Over $5,000 needs the CFO as well" is logic your agent writes and you test. Real products have it built, with delegation when an approver is away.
  • Two roles, not ten. Admin and user. Budgets per department, or approvers per cost centre, are the app's own logic.
  • No approving from the email. The button opens the app, and the approval happens there, signed in.
  • No cards, no payments, no purchase orders sent to suppliers. It records a decision. Buying the thing is still done elsewhere.
  • Undoing code isn't undoing data. spry rollback changes the code that runs, not the records. Ask the agent for an admin-only CSV export and use it.

For a team of 10 to 50 that approves a few dozen purchases a month and needs a trustworthy record, the small app is often enough. For a finance team that needs controls an auditor will test, buy the product.

Start here

In Claude Code:

/plugin marketplace add spryloom/claude-plugin
/plugin install spryloom@spryloom

In Cursor or any MCP agent, use npx -y spryloom mcp as the server command. Then send the prompt above, and say "publish it with Spryloom for the office". Before inviting the office, invite a second address of your own as a user, sign in with it, and try to approve a request; the server should refuse. How to test an AI-built app before coworkers use it has the full two-account check.

Spryloom publishes apps and pages built with a coding agent behind sign-in, for the people you invite. This article was written by the people building it.

Get started free