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.
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
Your order form sends each new order to your automation's link.
ClickRuntime finds the customer in Xero by name, creating them if they're new.
It creates an approved invoice with the ordered items and downloads its PDF.
AI writes a short thank-you note.
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
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 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?
Is the invoice approved in Xero?
What if AI isn't available?
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 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.
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 worksGet error alerts with a plain-English explanation
When one of your jobs or systems fails, #ops gets the error and a one-line guess at the cause, without the same error twice in an hour.
See how it worksKeep exploring
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.