Quick Overview
This workflow polls a Google Sheets milestone tracker every 15 minutes, calculates milestone-based invoice amounts, uses OpenAI (gpt-4o-mini) to draft invoice messaging, emails the invoice via Gmail with an approval link, then records approval in Google Sheets and notifies an accounts Slack channel.
How it works
- Runs every 15 minutes and reads milestone rows from a Google Sheets “Milestones” tab.
- Filters for milestones where % Complete is at or above the Invoice Trigger % and the Invoice Status is Pending.
- Calculates the billable amount, generates an invoice ID, and asks OpenAI (gpt-4o-mini) to return a JSON invoice narrative, payment terms, email subject, and HTML email body.
- Builds an approval URL token, generates a styled HTML invoice document, and sends the invoice email to the client via Gmail with an Approve Invoice button.
- After the email step returns an approval result, updates the milestone status to Sent, appends a record to the Google Sheets “Invoice Log” tab, and stamps the approval timestamp in the Milestones tab.
- Posts a Slack message to the accounts team with the milestone ID and approval timestamp, and sends a Slack alert if the workflow errors.
Setup
- Add Google Sheets OAuth2 credentials and replace the spreadsheet document ID and sheet tabs for both the “Milestones” and “Invoice Log” operations.
- Add an OpenAI credential (used with the gpt-4o-mini model) and adjust the prompt/model if you want different invoice wording.
- Add a Gmail OAuth2 credential and update the recipient address in the Gmail node ([email protected]) to your client email field or target address.
- Add Slack OAuth2 credentials and replace both Slack channel IDs (error alerts and accounts notifications) with your workspace channels.
- Replace YOUR_N8N_WEBHOOK_BASE_URL in the approval URL builder with your live n8n base URL and ensure your Milestones sheet includes the required columns (Milestone ID, Contract ID, Client Name, % Complete, Invoice Trigger %, Contract Value ($), Invoice Status, Currency).