Quick Overview
This workflow monitors Gmail for emails with PDF attachments, extracts invoice fields with OpenAI, logs the results to a Google Sheets bookkeeping spreadsheet, and posts high-value invoices to Slack for approval.
How it works
- Triggers every minute when Gmail finds a new email matching the search query and downloads its attachments.
- Extracts text from the first PDF attachment in the email.
- Sends the extracted text to OpenAI (gpt-4o-mini) to return structured invoice data (vendor, dates, amounts, currency, category, and summary) as JSON.
- Appends the extracted invoice fields to a Google Sheets worksheet and marks the entry as Unpaid with the current received timestamp.
- Checks whether the invoice total is greater than or equal to 1000.
- Posts a Slack message to a selected channel to request approval for invoices that meet the high-value threshold.
Setup
- Connect your Gmail, OpenAI, Google Sheets, and Slack credentials in n8n.
- Update the Gmail search query in the Gmail trigger to target the invoice emails you want to process (for example, by label, sender, or subject).
- Replace YOUR_GOOGLE_SHEET_ID with your spreadsheet ID and ensure the target sheet has columns matching Vendor, Invoice #, Invoice Date, Due Date, Currency, Category, Tax, Total, Status, and Received.
- Set the Slack channel to post into and adjust the approval threshold amount (currently 1000) to match your policy.