Every 15 minutes
Turn emailed supplier invoices into Xero draft bills
Supplier invoices that arrive in Gmail become draft bills in Xero with the PDF attached, ready for you to approve.
- Runs
- Every 15 minutes
- Apps
- Gmail, Xero
- AI
- Yes, uses the built-in AI allowance
- Access
- Gmail modify; accounting.transactions
Send this to your assistant
Create a ClickRuntime automation: every 15 minutes, check Gmail for invoice attachments, read them with AI, create a draft bill in Xero with the PDF attached, and label the email as processed.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
Bookkeepers spend hours a week turning PDF invoices into Xero bills: open the attachment, find the supplier, type the reference, date and amount, attach the file. It's repetitive, and when it falls behind, the business loses sight of what it owes.
Creating draft bills as invoices arrive means the bookkeeper's job becomes checking and approving. Drafts don't affect your accounts until approved, so control stays with a person.
What you get out of it
Bills appear as invoices arrive
Payables in Xero match your inbox, so cash planning is based on what you really owe.
Approval stays manual
Everything lands as a draft. Nothing is posted until someone approves it in Xero.
Original PDF attached
Every draft bill carries the supplier's file, so checking it takes one click.
Handled emails are labelled
A Processed label shows which invoices are done, and stops any being created twice.
How it works
What happens, step by step
Every 15 minutes, ClickRuntime checks Gmail for new emails with PDF invoices that haven't been processed.
AI reads each email and picks out the supplier, reference, date, due date and total.
It creates a draft bill in Xero and attaches the PDF.
It labels the email as processed so it's never handled twice.
Before it runs live
- Connect Google through your own Google app (a one-time, 10-minute setup), so it works with your own Gmail
- Connect Xero
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 Gmail and Xero steps into one automation
Under the hood
The code that runs this automation
import base64
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_trigger, credentials, http, ai, report_fetched
XERO = "https://api.xero.com/api.xro/2.0"
TENANT = "your-xero-tenant-id"
def xero(method, path, **kw):
r = http.request(method, XERO + path, **kw, headers={"Accept": "application/json", "Xero-tenant-id": TENANT, "Authorization": "Bearer " + credentials.connection("xero", "company")})
return r.raise_for_status() or r.json()
PROCESSED = "Label_Processed" # id of your Gmail label
SCHEMA = {"type": "object", "properties": {k: {"type": "number" if k == "total" else "string"} for k in ("supplier", "reference", "date", "due", "total")}}
@on_trigger
def run(event):
gmail = build("gmail", "v1", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False)
msgs = gmail.users().messages().list(userId="me", q="has:attachment filename:pdf label:Invoices -label:Processed").execute().get("messages", [])
report_fetched(len(msgs))
if not msgs:
return {"summary": "Nothing new"}
for m in msgs:
full = gmail.users().messages().get(userId="me", id=m["id"]).execute()
part = next(p for p in full["payload"]["parts"] if p.get("filename", "").lower().endswith(".pdf"))
pdf = base64.urlsafe_b64decode(gmail.users().messages().attachments().get(userId="me", messageId=m["id"], id=part["body"]["attachmentId"]).execute()["data"])
f = ai.generate(f"Extract supplier, reference, date and due (YYYY-MM-DD), total:\n{full['snippet']}", json_schema=SCHEMA, max_output_tokens=120).json
bill = xero("PUT", "/Invoices", json={"Invoices": [{"Type": "ACCPAY", "Status": "DRAFT", "Contact": {"Name": f["supplier"]},
"InvoiceNumber": f["reference"], "Date": f["date"], "DueDate": f["due"], "LineAmountTypes": "Inclusive",
"LineItems": [{"Description": f"Invoice {f['reference']}", "Quantity": 1, "UnitAmount": f["total"], "AccountCode": "400"}]}]})["Invoices"][0]
xero("PUT", f"/Invoices/{bill['InvoiceID']}/Attachments/{part['filename']}", data=pdf, params={"IncludeOnline": "false"})
gmail.users().messages().modify(userId="me", id=m["id"], body={"addLabelIds": [PROCESSED]}).execute()
return {"bills": len(msgs)}FAQ
Common questions
Does it create new suppliers in Xero?
Which emails does it read?
What about structured e-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
Create a Xero invoice for each order and email it to the customer
When an order comes in, a Xero invoice is created and emailed to the customer from your Gmail with the PDF and a short personal note.
See how it worksSend Xero payment reminders that get firmer over time
Customers with overdue Xero invoices get a reminder from your Gmail at 7, 14 and 30 days late, each a little firmer, and you get a daily summary.
See how it worksLabel new emails automatically
New mail is sorted into labels like Inquiry, Invoice and Newsletter within minutes of arriving.
See how it worksKeep exploring
Set up “Turn emailed supplier invoices into Xero draft bills” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.