Quick overview
This workflow watches a Google Drive folder for new invoice images, extracts key invoice fields with OpenAI vision, checks for duplicates in Postgres, and then stores the invoice or moves the file into processed, duplicate, or failed folders.
How it works
- Triggers every hour when a new file is created in a specific Google Drive folder.
- Downloads the new file from Google Drive and sends the image to OpenAI (GPT-4o) to extract invoice fields as JSON.
- Cleans and parses the AI response into structured invoice data, routing invalid or unparseable results to a failed path.
- Checks Postgres to see if an invoice with the same vendor name, invoice number, and total already exists.
- If the invoice is a duplicate, moves the source file in Google Drive to a duplicate folder.
- If the invoice is not a duplicate, inserts the invoice into the Postgres invoices table (status set to processed) and moves the source file to a processed folder.
Setup
- Connect Google Drive OAuth2 credentials and set the incoming, processed, duplicate, and failed folder IDs to match your Drive structure.
- Add an OpenAI API credential and ensure the selected model (gpt-4o) is available for image analysis.
- Add Postgres credentials and create an invoices table with columns for vendor_name, invoice_number, invoice_date, due_date, currency, subtotal, tax, total, po_number, and status.