Turn vendor invoice emails into draft bills in Xero

By General Input

Every 30 minutes, this agent reads new supplier invoice emails in Gmail, drafts the bill in Xero, and asks for approval in Slack.

Integrations

  • Xero
  • Gmail
  • Slack

Type

Agentic Task

Categories

  • Finance
  • Operations

Build me an agent workflow that ingests vendor invoice emails from Gmail and turns them into draft bills in Xero with a Slack approval card. Run it on a cron schedule every 30 minutes.

On each run the agent should: (1) Call Gmail List Messages with a query that filters to a configurable label (default: vendor-invoices) and excludes any message that already carries the processed label (default: processed-to-xero). Make the label names configurable. (2) For each new message, call Gmail Get a Message with full detail level to retrieve the email body, headers, and any PDF attachments.

Use the model to extract the following fields from the email body and any PDF attachments: vendor name, vendor email or domain, invoice number, issue date, due date, currency, subtotal, tax amount, total amount, and line items (description, quantity, unit price, line total, and tax rate if present). Include a short confidence note describing how clean the extraction was and which field, if any, looked uncertain.

Then ensure the supplier exists in Xero. Look up the contact by vendor name (and email if available). If no match exists, call Xero Create Contacts to create the supplier with IsSupplier=true and the email/domain on file. Take the resulting ContactID.

Call Xero Create Invoices with Type=ACCPAY, Status=DRAFT, the supplier ContactID, the extracted invoice number as InvoiceNumber, the issue date as Date, the due date as DueDate, the currency code, and the extracted line items mapped to LineItems (Description, Quantity, UnitAmount, and TaxAmount or TaxType where possible). Put the Gmail message permalink (https://mail.google.com/mail/u/0/#inbox/<messageId>) in the Reference field so reviewers can jump back to the source email from Xero.

After the bill is created, call Gmail Modify Message Labels on the original message to add the processed label (default: processed-to-xero) and remove UNREAD so the next run skips it. If the processed label does not exist yet, create it first.

Finally, post an approval card in Slack via Slack Send a Message to a configurable channel. The message should include: vendor name, invoice number, issue date, due date, currency, total amount, tax amount, a one-line summary of line items, a link to the draft bill in Xero, a link to the source Gmail message, and the AI confidence note. Make it clear the bill is in DRAFT and needs a human to approve in Xero before payment.

Configurable inputs: Gmail watch label, processed label, Slack approval channel, Xero organization (tenant) if the user has multiple, and an optional sender allowlist (only ingest messages from these domains). Skip and log any message where extraction fails or the total is missing, and do NOT apply the processed label in that case so a human can re-run it after fixing the source.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentWin back LiveChat visitors whose chats went unansweredChat quality review board for LiveChat support leadsChase the paperwork every new client and vendor still owesFile Gmail attachments into storage with names you can findWin back no-show and cancelled appointments every morningLive Loop returns analytics with product-level drill-downNewsletter pre-flight and approval board for Mailjet sendsTurn a prospect spreadsheet into personalized sequence enrollmentsMailjet email delivery lookup console for support teams