# 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), “

- **Domain**: `n8n-workflow-23392.n8n.io`
- **Provider**: n8n.io (https://n8n.io)
- **Kind**: workflow
- **Live-responds (last probe)**: None
- **Signed card**: False
- **Streaming**: False
- **Quality score**: 40%

## URLs
- Agent card: https://n8n.io/workflows/23392
- Page (HTML): https://agenstry.com/agents/n8n-workflow-23392.n8n.io
- Documentation: https://n8n.io/workflows/23392
