Skip to main content
Clever Ops

Case studyReal job

How we built a Xero invoice chaser that finds the payer

We built an invoice chaser for a services business in Australia that reads overdue sales invoices from Xero each morning, finds the person who pays in the invoice's line text, and emails them a reminder from the business's accounts mailbox.

  • XeroOverdue sales invoices
  • OpenAIReads the invoice lines
  • ClaudeDrafts the reminders
  • GmailSends the reminders
  • SlackTells the team

Transcript

This is a made-up overdue invoice going through software we built for a services business in Australia. The reminder goes to the person who pays it. That person isn't the contact on the invoice in Xero. Their name and email were typed into the invoice lines, and the system found them there.

They first got in touch by email, asking how automation and AI could help them. The first job they took on with us was an email agent on their sales inbox. This film is about the second: an invoice chaser, which came out of a call about overdue invoices.

Their overdue reminders went to whoever was on file in Xero, and that was sometimes someone other than the person who pays. Their team typed the right person's name and email into the invoice lines by hand, but the reminders didn't use them.

Xero's API works the same way. When Xero sends an invoice by email, its documentation says it goes to the contact's primary address and any contact people flagged for emails. A name typed into a line isn't part of that.

Here's what runs now. Each morning the system pulls approved sales invoices from Xero and keeps the ones past their due date. It sends each invoice's line text to an OpenAI model, which picks out names and email addresses. Anything at the business's own domain is dropped.

If it can't find anyone, it doesn't guess. It emails the account managers and posts in Slack, once per invoice, so a person can fix the lines. If it does find the payer, it checks when that invoice was last chased. At the first stage it waits fourteen days between reminders, and seven after that.

Claude drafts the reminder from the business's own templates. There are four, one for each stage, set by how many days overdue the invoice is. The email goes from their accounts mailbox through Gmail, with their own staff on blind copy and a link to the invoice online.

Then the system writes a note on the invoice's history in Xero, saying what was sent and to whom, and posts the email in Slack. A setting can hold every email for approval in Slack first. A person still types the payer into the invoice, fixes anything the system flags, and decides what happens next with anything ninety days overdue, which gets its own alert.

Now the detail. The system reaches Xero through a Custom Connection: one organisation, machine to machine, without anyone logging in. Xero's API returns each invoice with its contact, due date, amount due and line items, and each line has a free-text description. That's where the payer was typed.

Free text is why there's a model in it. The OpenAI call asks for names and emails as JSON. OpenAI's docs say that mode gives valid JSON, not that it matches the shape you asked for. So our code checks each address itself and drops the business's own domain again. If nothing's left, a person is told, and no reminder goes out.

Sending goes through the Gmail API from the accounts mailbox, so replies come back to that mailbox. Each send is recorded in a Postgres table, and that record is what holds back a second reminder inside the waiting period. The note in Xero means anyone who opens the invoice can see what went out.

Two small rules carry a lot of weight. If Claude's draft leaves out the invoice link, the code puts it back. And if Claude can't be reached, the template goes out as written, so a reminder doesn't wait on a model.

It's been running since February 2026, alongside the email agent. There's no result figure in this film. And a reminder is only a reminder. It gets to the person who pays, and paying is still up to them.

If your overdue reminders are going to the wrong person in Xero, get in touch.

Each reminder is noted on the invoice in Xero and posted to Slack. An invoice with nobody to email goes to a person instead.

How and why they came

They first got in touch by email, asking how automation and AI could help them. The first job they took on with us was an email agent on their sales inbox. The invoice chaser came next, out of a call about overdue invoices.

The problem

Their overdue reminders went to whoever was on file in Xero, and that was sometimes someone other than the person who pays. The team typed the right person's name and email into the invoice lines by hand, but the reminders didn't use them.

Xero's API works from the contact as well. When it emails an invoice, the email goes to the contact's primary address and any contact persons set to receive emails. A name typed into a line isn't part of that.1

Documentation

  1. 1Emailing an invoice

What we built

  1. 1
    Xero

    A daily read of Xero

    Each morning the system fetches approved sales invoices and keeps those past their due date.

  2. 2

    Finding the payer

    The line text goes to an OpenAI model, which returns names and email addresses. Addresses at the business's own domain are dropped.

  3. 3

    Nobody found, nobody emailed

    If no address is left, the account managers get an email and a Slack message, once per invoice, asking for the lines to be fixed.

  4. 4

    Waiting periods

    A tracking table stops the same invoice being chased again within 14 days at the first stage, or within 7 days at later stages.

  5. 5
    Claude

    The reminder

    Claude drafts it from the business's own templates, one for each of four stages: 1 to 29 days overdue, 30 to 59, 60 to 119, and 120 or more. It goes from the accounts mailbox through Gmail, with staff on blind copy and a link to the invoice online.

  6. 6
    Xero

    The record

    A note goes on the invoice's history in Xero, and the email is posted in Slack. Invoices 90 days or more overdue raise a separate alert.

A setting can hold every email for approval in Slack first, with Approve and Skip buttons, instead of sending directly.

A sample invoice in Xero's Demo Company, and the system's own output

  • The contact on file, and the payer typed into the invoice line.

    Xero Demo Company. Sample data.

  • The reminder, sent to the person who pays.

    The system's own output. Sample data.

  • The note the system added to the invoice's history in Xero.

    Xero Demo Company. Sample data.

  • The next run skips invoices chased inside the waiting period.

    The system's own output. Sample data.

What a person still does

Staff type the payer into the invoice lines, fix any invoice the system flags, and decide what happens next with anything 90 days or more overdue. The business writes its own reminder wording.

The technical detail

What each system allowed

Xero

  • A Custom Connection uses the client credentials grant to reach one Xero organisation, for back-end, machine-to-machine integrations.12
  • The Invoices endpoint can filter by status, and an AUTHORISED invoice is one that's approved and awaiting payment.34
  • Each invoice comes back with its contact, due date, amount due and line items, and each line carries a description.
  • The API returns an online invoice link for sales invoices that aren't drafts, and it can add a note to an invoice's history.3

OpenAI

  • The call asks for JSON.
  • OpenAI's documentation says JSON mode produces valid JSON but, unlike Structured Outputs, doesn't ensure it follows a schema.1
  • So the code checks each address itself.

Documentation

  1. 1Structured Outputs

Gmail

  • The Gmail API's send method sends a message to the recipients in its To, Cc and Bcc headers.1
  • Reminders go from the accounts mailbox, so replies come back there.

Documentation

  1. 1Send a message

Slack

  • Messages are sent with chat.postMessage, built from blocks.1

Documentation

  1. 1Post a message

Vendor links checked 15 November 2026.

Design decisions

  • The model reads, the code checks

    The model is told to leave out the business's own addresses, and the code drops them again. An entry without an @ is thrown away.

  • No address, no email

    If nothing is left, a person is told instead.

  • The link goes back in

    If a draft leaves out the invoice link, the code adds it before the sign-off.

  • A fallback for the drafting

    If Claude can't be reached, the template goes out as written, with the invoice details filled in.

  • A trail in Xero

    Each send adds a history note to the invoice, so anyone who opens it can see what was sent and to whom.

The hard parts

  • Free text

    The payer is typed by hand into a description field, alongside the rest of the line. That's why a language model reads it, and why the code checks what comes back.

  • Reading the lines, not the PDF

    We'd scoped reading the invoice PDF. The API returns the line text directly, so the system reads that.

How exceptions reach a person

No usable address
An email to the account managers and a Slack message listing the invoice, once per invoice.
Every run
A summary in Slack with the overdue invoices, emails sent and skipped, missing contacts and errors.
90 days or more overdue
A separate Slack alert for a person to review.
A failed run
An error alert in Slack.

An invoice with no address in its lines, flagged to the team.

The system's own output. Sample data.

Where it stands

Running since

February 2026

  • It's been running since February 2026, alongside the email agent.
  • The system gets each reminder to the person named as the payer. Whether and when they pay is up to them.

There's no result figure on this page.

Questions

Can Xero send overdue reminders to someone other than the invoice contact?

Through the API, Xero's invoice email goes to the contact's primary email address and any contact persons set to receive emails. On this job the payer was typed into the invoice lines, so our system reads them and sends the reminder itself through Gmail.

Does an AI model decide who gets chased?

A model reads the line text and returns names and email addresses. Our code checks each address, drops the business's own domain, and if nothing is left it tells a person instead of sending.

Will it email the same customer every day?

No. Each send is recorded, and the same invoice isn't chased again within 14 days at the first stage, or within 7 days after that.

Can someone approve each reminder before it goes?

Yes. A setting posts each draft to Slack with Approve and Skip buttons and keeps a Gmail draft ready, instead of sending directly.

Who writes the reminder wording?

The business does. The system drafts from their own templates. We don't give legal or collections advice.

Reminders going to the wrong person in Xero?

Book Free Assessment

Product names and logos belong to their owners and are shown to identify the systems connected.