Every 15 minutes
Check emailed invoices against your purchase order sheet
Invoices arriving in Outlook are read, matched to your purchase orders in a sheet, and anything that doesn't match is flagged to you.
- Runs
- Every 15 minutes
- Apps
- Google Sheets, Outlook
- AI
- Yes, uses the built-in AI allowance
- Access
- Mail.Read; sheet edit
Send this to your assistant
Create a ClickRuntime automation: every 15 minutes, check Outlook for new emails with PDF attachments. If one is an invoice, read the PO number, supplier and total with AI, find the PO in my Purchase Orders sheet, mark it invoiced if the amount matches, and email me if it doesn't match or the PO isn't found.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A small manufacturer's finance assistant matches every supplier invoice to a purchase order before it is paid. Invoices arrive by email as PDFs, and the matching means opening each one, finding the PO in a sheet and comparing amounts. Mistakes and overcharges slip through when the pile gets big.
Reading each invoice as it arrives and checking it against the PO sheet means the assistant only looks at the ones that don't match.
What you get out of it
Overcharges are caught
Invoices that don't match the agreed amount are flagged before they are paid.
Matching done as invoices arrive
The sheet shows which POs have been invoiced without anyone opening PDFs.
Attention where it is needed
Only mismatches and unknown POs come to you; matched invoices are simply recorded.
Works with your existing sheet
Your purchase order sheet stays the source of truth.
How it works
What happens, step by step
Every 15 minutes, ClickRuntime checks Outlook for new emails with PDF attachments.
It reads the text of each PDF and AI pulls out the PO number, supplier and total, or says it is not an invoice.
The PO number is looked up in your Purchase Orders sheet.
If the total matches, the PO is marked invoiced; if not, or the PO is missing, you get an email with the details.
Before it runs live
- Connect your Google Sheets account and pick the spreadsheets it may use
- Connect Outlook
What you get
Build your own
Need it to work differently?
Your own rules
Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.
Any number of apps
One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.
AI where it helps
Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.
On a schedule or on each event
Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.
Changes you can ask for
- Act only on the items that match your own rules, and skip the rest
- Change what the AI looks for, or how it writes the result
- Add another app, for example also send it to Slack
- Combine it with other Google Sheets and Outlook steps into one automation
Under the hood
The code that runs this automation
import base64
import io
from pypdf import PdfReader
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_trigger, report_fetched, http, credentials, ai, state, notify
api = lambda name, version: build(name, version, credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False)
def graph(method, path, **kw):
r = http.request(method, "https://graph.microsoft.com/v1.0" + path, headers={"Authorization": f"Bearer {credentials.connection('microsoft', 'work')}"}, **kw)
return r.raise_for_status() or (r.json() if r.content else None)
pdf_text = lambda b64: " ".join(p.extract_text() or "" for p in PdfReader(io.BytesIO(base64.b64decode(b64))).pages)[:12000]
SHEET_ID = "your-spreadsheet-id"
SCHEMA = {"type": "object", "properties": {"invoice": {"type": "boolean"}, "po": {"type": "string"}, "supplier": {"type": "string"}, "total": {"type": "number"}}}
@on_trigger
def run(event):
since = state.get("since") or "2026-01-01T00:00:00Z"
msgs = graph("GET", "/me/messages", params={"$filter": f"hasAttachments eq true and receivedDateTime gt {since}", "$orderby": "receivedDateTime", "$top": 25})["value"]
report_fetched(len(msgs))
if not msgs:
return {"summary": "No new attachments"}
sheet = api("sheets", "v4").spreadsheets().values()
pos = {r[0]: (n, r) for n, r in enumerate(sheet.get(spreadsheetId=SHEET_ID, range="Purchase Orders!A2:D").execute().get("values", []), start=2) if r}
for m in msgs:
for a in graph("GET", f"/me/messages/{m['id']}/attachments")["value"]:
if a.get("contentType") != "application/pdf":
continue
inv = ai.generate(pdf_text(a["contentBytes"]), system="Is this an invoice? Extract PO number, supplier and total.", json_schema=SCHEMA, max_output_tokens=100).json
n, row = pos.get(inv.get("po", ""), (None, None))
if inv["invoice"] and row and abs(float(row[2]) - inv["total"]) < 0.01:
sheet.update(spreadsheetId=SHEET_ID, range=f"Purchase Orders!D{n}", valueInputOption="RAW", body={"values": [["invoiced"]]}).execute()
elif inv["invoice"]:
notify.email_me(f"Invoice mismatch: {inv.get('supplier')}", f"PO {inv.get('po') or 'missing'}: invoice {inv['total']}, PO {row[2] if row else 'not found'}")
state.set("since", msgs[-1]["receivedDateTime"])
return {"checked": len(msgs)}FAQ
Common questions
What if an invoice has no PO number?
How close must the amounts be?
Does it pay invoices?
What permissions does it need?
Does it need AI?
How many runs does it use?
Can I change how it works?
Related
You might also like
Sort your Outlook inbox with AI and log it to a sheet
New emails get an Outlook category and a one-line summary in a sheet, and simple questions get a reply draft waiting for you.
See how it worksLog each sale to a sheet and send a thank-you from Outlook
Every new sale is added to your sales sheet and the buyer gets a personal thank-you email from your Outlook address.
See how it worksEmail new leads in your sheet from Outlook
Each new lead added to your sheet gets a personal email from your Outlook, and the row is marked as sent with the date.
See how it worksKeep exploring
Set up “Check emailed invoices against your purchase order sheet” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.