See llms.txt for all machine-readable content.

Back to Templates

Match supplier invoices to purchase orders and post to Xero, QuickBooks, or Sheets using Gmail, OpenAI, and Telegram

Quick overview

Reads invoice PDFs from Gmail, matches every one to its purchase order, asks a human on Telegram to approve anything that does not reconcile, and posts approved bills to Xero or QuickBooks exactly once.

How it works

  1. A Gmail trigger polls a label every five minutes and keeps only PDF attachments. The file is converted to text, then an HTTP node asks any OpenAI-compatible model for one JSON object holding vendor, invoice number, dates, currency, subtotal, tax, total, line items, VAT and PO number.
  2. A code node repairs what models get wrong: decimal commas such as 1.234,56, dd/mm/yyyy dates and currency symbols, and every amount is recomputed in code. The If gate requires vendor, number, date, currency and total, and requires subtotal plus tax to equal the stated total within two cents; anything else goes to Telegram review instead of the ledger.
  3. The ledger is read next (an empty sheet still lets the first invoice through) and keyed on normalised vendor plus invoice number, so a supplier that re-sends the same PDF produces one row and one alert, never two payments.
  4. Read Purchase Orders and the match node then run the three-way match: the PO number must exist, it must belong to this vendor, and the total must fit the open balance (po_amount minus invoiced_to_date). Invoices at or above the approval threshold ask as well.
  5. Anything unmatched is sent to Telegram with Approve and Reject buttons built from the execution resume URL, and the Wait node holds the run open until a human decides. Approve writes the ledger row and continues; Reject files the invoice in the Rejected Invoices register with its reason, so the ledger stays clean and a corrected invoice can be submitted again.
  6. A Switch then routes approved bills to Xero as an ACCPAY bill, to QuickBooks as a bill, or stops at the sheet. Posting carries an Idempotency-Key header and three retries, and failures escalate to Telegram with the ledger row left intact.
  7. Appends approved invoices to the Google Sheets ledger and routes them to Xero or QuickBooks for bill creation (or leaves them in Sheets), while rejected invoices are written to a separate “Rejected Invoices” sheet and posting failures are escalated in Telegram.

Setup

  1. Connect Gmail (OAuth2) and create a label such as Invoices with a filter matching your suppliers' PDFs. Connect Google Sheets and create three tabs: Ledger (leave it empty - the append node writes the fields it receives, including invoice_key, match_status, approval_status and processed_at), PurchaseOrders (po_number, vendor, po_amount, invoiced_to_date, currency) and Rejected Invoices.
  2. Create an HTTP Header Auth credential for any OpenAI-compatible provider (OpenAI, DeepSeek, OpenRouter, Groq) and set the model name in the request body. Connect a Telegram bot credential and put your chat ID on the four message nodes.
  3. Set TARGET_SYSTEM in the parse node to xero, quickbooks or sheets, and set APPROVAL_THRESHOLD in the match node to the value above which you always want to approve by hand. For accounting systems, replace the placeholder URL and connect the OAuth2 credential, then map the account code to your own chart of accounts. Test on three real invoices before enabling the trigger.
  4. Create a Telegram bot, add Telegram API credentials, and set your target chat ID for review, approval, duplicate, rejection, and failure notifications.
  5. If posting to Xero or QuickBooks, connect the respective OAuth2 credentials and fill in required values like Xero account code, QuickBooks realm ID, and QuickBooks account ID, then set the TARGET_SYSTEM value to xero, quickbooks, or sheets and adjust the approval threshold in the matching logic.

Requirements

  • A Gmail account with a labelled invoice feed, a Google Sheet with the Ledger, PurchaseOrders and Rejected Invoices tabs (or your own purchase-order source), an OpenAI-compatible API key and a Telegram bot. Xero or QuickBooks OAuth2 credentials are only needed if bills are posted into an accounting system.

Customization

  • Point Read Purchase Orders at Airtable, a database or your ERP instead of a sheet, make the approval threshold per vendor instead of global, add a second approver above a ceiling, or swap Telegram for email or Slack approval using the same resume-URL pattern.