Every 15 minutes
Log invoice emails as payables in Airtable
Invoices that arrive by email are read and added to your Airtable payables table with vendor, amount, due date and invoice number.
- Runs
- Every 15 minutes
- Apps
- Airtable, Gmail
- AI
- Yes, uses the built-in AI allowance
- Access
- Gmail gmail.readonly; Airtable write
Send this to your assistant
Create a ClickRuntime automation: when an invoice email arrives, pull out the vendor, amount, due date and invoice number, and add it to my Airtable AP table.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A bookkeeper for a small business receives supplier invoices by email all month. Each one needs to be opened, read and typed into the payables table before it can be scheduled for payment. On busy weeks invoices sit unlogged, and late fees follow.
This automation reads each new invoice email and its PDF, pulls out the key fields, and adds a row to your Airtable payables table. Your payables list stays current without anyone typing it in.
What you get out of it
Fewer late payments
Every invoice is logged with its due date as soon as it arrives, so nothing waits in an inbox until after it is due.
Less typing, fewer typos
Amounts and invoice numbers are copied straight from the document instead of retyped, which cuts the errors that cause payment mix-ups.
A payables view everyone can use
Owners and accountants can see what is due this week in Airtable without asking for access to the inbox.
The original stays attached
Each row links back to the email, so checking a figure against the actual invoice takes one click.
How it works
What happens, step by step
Every few minutes ClickRuntime checks your Gmail for new emails with invoice attachments.
Emails it has already logged are skipped.
AI reads the invoice and picks out the vendor, amount, due date and invoice number.
A new row is added to your Airtable payables table with a link to the email.
Before it runs live
- Connect Airtable
- Connect Google through your own Google app (a one-time, 10-minute setup), so it works with your own Gmail
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 Airtable and Gmail steps into one automation
Under the hood
The code that runs this automation
import base64, io
from pypdf import PdfReader
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_trigger, credentials, http, ai, state, report_fetched
AP_URL = "https://api.airtable.com/v0/appXXXXXXXXXXXXXX/Payables"
SCHEMA = {"type": "object", "properties": {k: {"type": "string"} for k in ("vendor", "amount", "due_date", "invoice_number")}}
@on_trigger
def run(event):
gmail = build("gmail", "v1", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False)
seen = set(state.get("seen") or [])
msgs = [m for m in gmail.users().messages().list(userId="me", q="has:attachment filename:pdf (invoice OR bill) newer_than:2d")
.execute().get("messages", []) if m["id"] not in seen]
report_fetched(len(msgs))
if not msgs:
return {"logged": 0}
for m in msgs:
msg = gmail.users().messages().get(userId="me", id=m["id"]).execute()
part = next(p for p in msg["payload"].get("parts", []) if p.get("filename", "").lower().endswith(".pdf"))
data = gmail.users().messages().attachments().get(userId="me", messageId=m["id"], id=part["body"]["attachmentId"]).execute()["data"]
text = "\n".join(p.extract_text() or "" for p in PdfReader(io.BytesIO(base64.urlsafe_b64decode(data))).pages)[:6000]
f = ai.generate(f"Extract invoice fields (due_date as YYYY-MM-DD):\n{text}", json_schema=SCHEMA, max_output_tokens=150).json
http.post(AP_URL, headers={"Authorization": f"Bearer {credentials.secret('AIRTABLE_API_KEY')}"}, json={"typecast": True,
"records": [{"fields": {"Vendor": f.get("vendor"), "Amount": f.get("amount"), "Due": f.get("due_date") or None,
"Invoice #": f.get("invoice_number"), "Email": f"https://mail.google.com/mail/u/0/#all/{m['id']}"}}]})
seen.add(m["id"])
state.set("seen", list(seen)[-1000:])
return {"logged": len(msgs)}FAQ
Common questions
Which emails does it pick up?
What if a field cannot be read?
Can it work with scanned 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
Turn emails that ask for something into Airtable tasks
Emails that ask you to do something become tasks in Airtable, with a clear title, a due date and a priority.
See how it worksScreen CVs from email into an Airtable candidate list
Application emails become Airtable records with the candidate's details and a score for the role.
See how it worksQualify buyer enquiry emails into your Airtable CRM
Each buyer enquiry email becomes a scored Airtable record with budget, area and timeline already filled in.
See how it worksKeep exploring
Set up “Log invoice emails as payables in Airtable” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.