AutomationMart
Home/Browse/Automate invoice processing with OCR, GPT-4 & Salesforce opportunity creation
n8n

Automate invoice processing with OCR, GPT-4 & Salesforce opportunity creation

n8nn8n11 modulesv1.0
SalesforceOpenAIGoogle Drive

PDF Invoice Extractor (AI) End-to-end pipeline: Watch Drive ➜ Download PDF ➜ OCR text ➜ AI normalize to JSON ➜ Upsert Buyer (Account) ➜ Create Opportunity ➜ Map Products ➜ Create OLI via Composite API ➜ Archive to OneDrive. --- Node by node (what it does & key setup) 1) Google Drive Trigger - Purpose: Fire when a new file appears in a specific Google Drive folder. - Key settings: - Event: fileCreated - Folder ID: google drive folder id - Polling: everyMinute -

At a glance

Automate invoice processing with OCR, GPT-4 & Salesforce opportunity creation is a ready-made n8n workflow you import as a workflow JSON file — no build required. It connects Salesforce, OpenAI, Google Drive. It's free to download. Follow the 5-step import below to go live in minutes.

Platform
n8n
Connects
Salesforce, OpenAI, Google Drive
Modules
11
Price
Free
Version
v1.0
Automate invoice processing with OCR, GPT-4 & Salesforce opportunity creation workflow diagram

About this workflow

PDF Invoice Extractor (AI) End-to-end pipeline: Watch Drive ➜ Download PDF ➜ OCR text ➜ AI normalize to JSON ➜ Upsert Buyer (Account) ➜ Create Opportunity ➜ Map Products ➜ Create OLI via Composite API ➜ Archive to OneDrive. --- Node by node (what it does & key setup) 1) Google Drive Trigger - Purpose: Fire when a new file appears in a specific Google Drive folder. - Key settings: - Event: fileCreated - Folder ID: google drive folder id - Polling: everyMinute - Creds: googleDriveOAuth2Api - Output: Metadata { id, name, ... } for the new file. --- 2) Download File From Google - Purpose: Get the file binary for processing and archiving. - Key settings: - Operation: download - File ID: ={{ $json.id }} - Creds: googleDriveOAuth2Api - Output: Binary (default key: data) and original metadata. --- 3) Extract from File - Purpose: Extract text from PDF (OCR as needed) for AI parsing. - Key settings: - Operation: pdf - OCR: enable for scanned PDFs (in options) - Output: JSON with OCR text at {{ $json.text }}. --- 4) Message a model (AI JSON Extractor) - Purpose: Convert OCR text into strict normalized JSON array (invoice schema). - Key settings: - Node: @n8n/n8n-nodes-langchain.openAi - Model: gpt-4.1 (or gpt-4.1-mini) - Message role: system (the strict prompt; references {{ $json.text }}) - jsonOutput: true - Creds: openAiApi - Output (per item): $.message.content → the parsed JSON (ensure it’s an array). --- 5) Create or update an account (Salesforce) - Purpose: Upsert Buyer as Account using an external ID. - Key settings: - Resource: account - Operation: upsert - External Id Field: taxidc - External Id Value: ={{ $json.message.content.buyer.taxid }} - Name: ={{ $json.message.content.buyer.name }} - Creds: salesforceOAuth2Api - Output: Account record (captures Id) for downstream Opportunity. --- 6) Create an opportunity (Salesforce) - Purpose: Create Opportunity linked to the Buyer (Account). - Key settings: - Resource: opportunity - Name: ={{ $('Message a model').item.json.message.content.invoice.code }} - Close Date: ={{ $('Message a model').item.json.message.content.invoice.issuedate }} - Stage: Closed Won - Amount: ={{ $('Message a model').item.json.message.content.summary.grandtotal }} - AccountId: ={{ $json.id }} (from Upsert Account output) - Creds: salesforceOAuth2Api - Output: Opportunity Id for OLI creation. --- 7) Build SOQL (Code / JS) - Purpose: Collect unique product codes from AI JSON and build a SOQL query for PricebookEntry by Pricebook2Id. - Key settings: - pricebook2Id (hardcoded in script): e.g., 01sxxxxxxxxxxxxxxx - Source lines: $('Message a model').first().json.message.content.products - Output: { soql, codes } --- 8) Query PricebookEntries (Salesforce) - Purpose: Fetch PricebookEntry.Id for each Product2.ProductCode. - Key settings: - Resource: search - Query: ={{ $json.soql }} - Creds: salesforceOAuth2Api - Output: Items with Id, Product2.ProductCode (used for mapping). --- 9) Code in JavaScript (Build OLI payloads) - Purpose: Join lines with PBE results and Opportunity Id ➜ build OpportunityLineItem payloads. - Inputs: - OpportunityId: ={{ $('Create an opportunity').first().json.id }} - Lines: ={{ $('Message a model').first().json.message.content.products }} - PBE rows: from previous node items - Output: { body: { allOrNone:false, records:[{ OpportunityLineItem... }] } } - Notes: - Converts discounttotal ➜ per-unit if needed (currently commented for standard pricing). - Throws on missing PBE mapping or empty lines. --- 10) Create Opportunity Line Items (HTTP Request) - Purpose: Bulk create OLIs via Salesforce Composite API. - Key settings: - Method: POST - URL: - Auth: salesforceOAuth2Api (predefined credential) - Body (JSON): ={{ $json.body }} - Output: Composite API results (per-record statuses). --- 11) Update File to One Drive - Purpose: Archive the original PDF in OneDrive. - Key settings: - Operation: upload - File Name: ={{ $json.name }} - Parent Folder ID: onedrive folder id - Binary Data: true (from the Download node) - Creds: microsoftOneDriveOAuth2Api - Output: Uploaded file metadata. --- Data flow (wiring) 1. Google Drive Trigger → Download File From Google 2. Download File From Google - → Extract from File - → Update File to One Drive 3. Extract from File → Message a model 4. Message a model - → Create or update an account 5. Create or update an account → Create an opportunity 6. Create an opportunity → Build SOQL 7. Build SOQL → Query PricebookEntries 8. Query PricebookEntries → Code in JavaScript 9. Code in JavaScript → Create Opportunity Line Items --- Quick setup checklist - 🔐 Credentials: Connect Google Drive, OneDrive, Salesforce, OpenAI. - 📂 IDs: - Drive Folder ID (watch) - OneDrive Parent Folder ID (archive) - Salesforce Pricebook2Id (in the JS SOQL builder) - 🧠 AI Prompt: Use the strict system prompt; jsonOutput = true. - 🧾 Field mappings: - Buyer tax id/name → Account upsert fields - Invoice code/date/amount → Opportunity fields - Product name must equal your Product2.ProductCode in SF. - ✅ Test: Drop a sample PDF → verify: - AI returns array JSON only - Account/Opportunity created - OLI records created - PDF archived to OneDrive --- Notes & best practices - If PDFs are scans, enable OCR in Extract from File. - If AI returns non-JSON, keep “Return only a JSON array” as the last line of the prompt and keep jsonOutput enabled. - Consider adding validation on parsing.warnings to gate Salesforce writes. - For discounts/taxes in OLI: - Standard OLI fields don’t support per-line discount amounts directly; model them in UnitPrice or custom fields. - Replace the Composite API URL with your org’s domain or use the Salesforce node’s Bulk Upsert for simplicity.

n8n

How to import this n8n workflow

  1. 1

    Download the workflow JSON file after purchase.

  2. 2

    Open n8n → click the menu → Import from File.

  3. 3

    Select the downloaded JSON and import.

  4. 4

    Set up credentials for each node that requires them.

  5. 5

    Click Execute Workflow to test, then activate.

Setup guide

Setup guide included

Purchase to unlock the full step-by-step guide

Related N8n workflows

Send automated emails using ChatGPT completions

This template sends personalized emails using ChatGPT completions. Trigger email actions with AI-generated content for engaging communication.

Free

Create email drafts using ChatGPT for new email triggers

Automatically draft emails with OpenAI GPT-3 when new email triggers occur. Streamline communication by generating content and creating drafts ready for review effortlessly.

Free

Generate biblical character vlogs with GPT-4o and Veo3 AI video generator

How It Works This intelligent workflow turns ancient stories and legendary characters into modern-style vlog ideas — then automatically builds cinematic prompts ready to generate short videos using Veo3. Think: “What if biblical figures had GoPros?” — funny, emotional, and visually stunning AI-made videos. --- 🔄 Workflow Steps ✨ 1. Concept Generator (AI Node 1) The first AI agent creates a video concept inspired by a biblical or mythological theme. It structures output as JSON with: 🎬 caption –

Free

Cross-post Tiktok videos to multiple social media platforms with RSS & Blotato

Description This automation detects when you post a Tiktok video, automatically downloads the video without watermark, stores it in Google Drive, and reposts your Tiktok video to other social media platforms. All on autopilot. So you can grow your presence on multiple platforms, without more work. You can also easily add steps to customize captions per platform. Youtube Tutorial 📄 Documentation [Full Step-by-Step Documentation](

Free

Transcribe Telegram voice notes to Google Docs with OpenAI & DeepSeek summaries

This n8n workflow automates the process of transcribing a voice message received via Telegram, summarizing the transcription using an AI model, and then saving both the transcription and the summary to separate Google Docs in Google Drive. Here's a breakdown of the workflow: Telegram Trigger: The workflow is initiated when a new message is received on Telegram. Telegram Node: It retrieves the voice message file from Telegram using the fileid from the incoming message. OpenAI Node: The retriev

Free

Wix chat auto-responder with OpenAI GPT and email fallback

Wix Chat Auto-Responder with OpenAI GPT and Email Fallback This template connects Wix Chat with OpenAI via n8n to automate intelligent customer responses on your website only when no human has responded recently. It uses smart throttling, checks for member vs. anonymous visitors, pulls chat history, and optionally alerts support staff via email if AI shouldn't reply. Perfect for solopreneurs, agencies, or customer support teams looking to auto-handle conversations while maintaining a fallback sy

Free

AI-powered email processing autoresponder and response approval (Yes/No)

How it Works This workflow is designed to automate the process of handling incoming emails, summarizing their content, generating appropriate responses, and obtaining approval before sending replies. Below are the key operational steps: 1. Email Reception and Summarization: - The workflow starts with an Email Trigger (IMAP) node that listens for new emails in a specified inbox. - Once an email is received, its HTML content is processed by a Markdown node to convert it into plain text if necess

Free

Automatically create Linear issues from Gmail support request messages

This n8n template watches a Gmail inbox for support messages and creates an equivalent issue item in Linear. How it works A scheduled trigger fetches recent Gmail messages from the inbox which collects support requests. These support requests are filtered to ensure they are only processed once and their HTML body is converted to markdown for easier parsing. Each support request is then triaged via an AI Agent which adds appropriate labels, assesses priority and summarises a title and descript

Free

Reviews

No reviews yet

Be the first to buy and share your experience.

Leave a review

Sign in to share your experience with this workflow.

Log in to review
Free
No ratings yet

Create a free account to purchase workflows.

  • JSON blueprint — instant download
  • Setup guide PDF included
  • 5 downloads · valid 30 days
  • Works with n8n

Need help setting this up?

Book a 3-hour live setup session with an Agility consultant.

₹2,499/ session
3 hrs · video call
  • Configure live on Google Meet / Zoom
  • Free follow-up if workflow has defects
  • Platform expert assigned to you
Book installation session
Free