Skip to content

The moment it happens

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.

Runs
The moment it happens
Apps
Gmail, Xero
AI
Yes, uses the built-in AI allowance
Access
accounting write; Gmail send

Send this to your assistant

Create a ClickRuntime automation: when my order form posts to this link, find or create the Xero contact, create the invoice, and email the PDF from Gmail with a short friendly note written by AI.

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

A business taking orders through a simple form, not a full shop, ends up invoicing by hand: copy the customer into Xero, add the items, download the PDF, write an email. It's slow, and orders placed on a Friday aren't invoiced until Monday.

Creating and sending the invoice the moment the order arrives means customers can pay straight away, and nobody spends their afternoon on paperwork.

What you get out of it

  • Customers can pay straight away

    The invoice arrives minutes after ordering, while the purchase is still on their mind.

  • A personal email, not a system one

    The PDF comes from your Gmail address with a short note, which reads better than an automated Xero email.

  • Customers are kept tidy

    Returning customers are matched to their existing Xero contact instead of creating duplicates.

  • Nothing waits for the weekend

    Orders placed at any hour are invoiced immediately.

How it works

What happens, step by step

  1. Your order form sends each new order to your automation's link.

  2. ClickRuntime finds the customer in Xero by name, creating them if they're new.

  3. It creates an approved invoice with the ordered items and downloads its PDF.

  4. AI writes a short thank-you note.

  5. The invoice PDF and note are emailed to the customer from your Gmail address.

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
  • Paste your automation's link into the other app's webhook settings

What you get

RunsThe moment it happens
Create a Xero invoice for each order and email it to the customerjust nowSucceeded
Gmail · SentInvoice INV-0431 for your order – Hi Acme Ltd, thanks for ordering 2 Northwind display stands…

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.
create_and_email_xero_invoices_from_orders.pyexample
import base64
from email.message import EmailMessage
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_event, credentials, http, ai
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()

@on_event
def handle(event):
    order = event.json
    inv = xero("PUT", "/Invoices", json={"Invoices": [{"Type": "ACCREC", "Status": "AUTHORISED", "Reference": order.get("id", event.event_id),
               "Contact": {"Name": order["name"], "EmailAddress": order["email"]}, "DueDate": order.get("due"),
               "LineItems": [{"Description": i["name"], "Quantity": i["qty"], "UnitAmount": i["price"], "AccountCode": "200"} for i in order["items"]]}]})["Invoices"][0]
    r = http.get(f"{XERO}/Invoices/{inv['InvoiceID']}", headers={"Accept": "application/pdf", "Xero-tenant-id": TENANT,
                 "Authorization": "Bearer " + credentials.connection("xero", "company")})
    try:
        note = ai.generate(f"Write a two-sentence friendly thank-you for an order of {', '.join(i['name'] for i in order['items'])}.", max_output_tokens=80).text
    except ai.AIError:
        note = "Thank you for your order. Your invoice is attached."
    msg = EmailMessage()
    msg["To"], msg["Subject"] = order["email"], f"Invoice {inv['InvoiceNumber']} for your order"
    msg.set_content(f"Hi {order['name']},\n\n{note}\n\nTotal due: {inv['Total']:,.2f}")
    msg.add_attachment(r.content, maintype="application", subtype="pdf", filename=f"{inv['InvoiceNumber']}.pdf")
    gmail = build("gmail", "v1", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False)
    gmail.users().messages().send(userId="me", body={"raw": base64.urlsafe_b64encode(msg.as_bytes()).decode()}).execute()
    return {"invoice": inv["InvoiceNumber"]}

FAQ

Common questions

What does the order form need to send?
The customer's name and email, and a list of items with quantities and prices. Most form tools can post this to your automation's link.
Is the invoice approved in Xero?
Yes, it's created as approved so it can be paid, and appears in Xero like any other sales invoice.
What if AI isn't available?
A standard short note is used instead, and the invoice is still sent.
What permissions does it need?
accounting write; Gmail send. 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 for each event the app sends.
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 “Create a Xero invoice for each order and email it to the customer” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.