Skip to content

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.

Paste it into your assistant. It tells you what it will send or change before it runs live.

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

  1. Every 15 minutes, ClickRuntime checks Gmail for new emails with PDF invoices that haven't been processed.

  2. AI reads each email and picks out the supplier, reference, date, due date and total.

  3. It creates a draft bill in Xero and attaches the PDF.

  4. 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

RunsEvery 15 minutes
Turn emailed supplier invoices into Xero draft billstoday, 9:00Succeeded
Xero · Draft billsNorthwind Supplies · INV-2291 · due 15 Nov · 1,280.00 (PDF attached)

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • 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

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
emailed_supplier_invoices_become_xero_draft_bills.pyexample
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?
Yes, Xero matches the supplier by name and creates a contact if none exists. Review new contacts when approving the bill.
Which emails does it read?
Only messages with PDF attachments matching your Gmail search, such as a label or a list of supplier addresses.
What about structured e-invoices?
If suppliers send XML e-invoices, those can be read directly without AI, which is faster and more exact.
What permissions does it need?
Gmail modify; accounting.transactions. Nothing else in your accounts is used.
Does it need AI?
Yes. It uses ClickRuntime's built-in AI, so you don't need an OpenAI or Anthropic key. Every plan includes a monthly AI allowance.
How many runs does it use?
One run each time it checks. Checks that find nothing new and stop right away aren't counted.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

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.