See llms.txt for all machine-readable content.

Back to Templates

Extract and validate invoice PDFs from email with OpenAI, Sheets and Xero

Quick overview

This workflow monitors an IMAP inbox for invoice PDF attachments, extracts structured invoice fields with OpenAI, validates totals and dates, logs results to Google Sheets, and optionally creates draft bills in Xero while sending Slack alerts for duplicates, reviews, and failures.

How it works

  1. Triggers when a new email arrives via IMAP (or runs manually with sample invoices for testing).
  2. Splits each email into one item per PDF attachment and ignores non-PDF attachments.
  3. Extracts text from each PDF and flags files with too little text as scanned invoices.
  4. For non-scanned PDFs, uses OpenAI with a structured JSON schema to extract invoice fields and line items from the PDF text.
  5. Validates required fields, checks that line items plus tax match the total within a tolerance, and rejects unreadable or future invoice dates.
  6. Looks up the vendor and invoice number in the Google Sheets “Invoices” tab to detect duplicates, then routes invoices to “Invoices” (ok), “Needs review” (with a reason), or a duplicate Slack alert.
  7. Appends ok invoices to Google Sheets and, if configured, creates a DRAFT accounts-payable invoice (bill) in Xero using the extracted line items.
  8. Posts Slack alerts for invoices needing review, duplicates, and any step failures while continuing to process other attachments.

Setup

  1. Connect IMAP credentials for the mailbox that receives invoices and ensure the node is allowed to download attachments.
  2. Add an OpenAI credential for the LangChain OpenAI Chat Model used to extract fields.
  3. Create a Google Sheets spreadsheet with “Invoices” and “Needs review” tabs, connect Google Sheets credentials, and replace the spreadsheet URL/ID used by the read/append steps.
  4. Create a Slack incoming webhook and paste the webhook URL into the workflow configuration.
  5. (Optional) Connect Xero OAuth2 credentials, set your Xero tenant ID and an expense account code, and keep the tenant ID empty if you only want to log to Google Sheets.
  6. Review and adjust configuration values such as the OpenAI model ID, total tolerance, and minimum text character threshold for scanned PDFs.