Automate Invoice Processing with OCR, GPT-4 & Salesforce Opportunity Creation — n8n Workflow

Medium complexity Trigger11 nodes🏷️ Invoice Processing👁 4 viewsby Le Nguyen

Overview

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**

Nodes used

HTTP RequestGoogle DriveMicrosoft OneDriveSalesforceCodeOpenAI

Workflow Preview

PDF Invoice Extractor (AI) to Salesforce Oppo
What it does:
Watch a Drive folder → OCR PDF → extract invoices (JSON
1) Google Drive Trigger
- Op: fileCreated in folder (ID)
- Poll: every minute
- Creds: Google Drive OAuth2
- Note: Ensure access/Shared Drive rights
2) Download from Drive
- Op: download by {{$json.id}}
- Binary key: data (default)
- Creds: Google Drive OAuth2
3) Extract from File
- Op: pdf (enable OCR for scans)
- Output: {{$json.text}}
4) Message a Model (JSON)
- Node: @n8n/n8n-nodes-langchain.openAi
- Model: gpt-4.1 (or gpt-4.1-mini)
- Prompt: strict schema; return only JSON array
- jsonOutput: true
- Output path (first item
5) Salesforce: Upsert Account (Buyer)
- Node: salesforce (account upsert)
- External Id: tax_id__c
- externalIdValue: ={{ $json.message.content.buyer.tax_
- name: ={{ $json.message.content.buy
6) Salesforce: Create Opportunity
- Node: salesforce (resource: opportunity)
- name: ={{ $('Message a model').item.json.message.cont
- closeDate: ={{ $('Message a model').item.js
7) Code: Build SOQL (PricebookEntry)
- Node: Code (JS)
- Purpose: collect ProductCodes from LLM products → bui
- Output: { soql, codes }
8) Salesforce: Query PricebookEntries
- Node: salesforce (search)
- query: ={{ $json.soql }}
9) Code: Build OLI Payloads
- Node: Code (JS)
- Inputs:
- OpportunityId: ={{ $('Create an opportunity').first
- Lines: ={{ $('Message a model').first().json.messag
10) HTTP Request: Create Opportunity Line Ite
- Method: POST
- URL: https://<your-instance>.my.salesforce.com/servic
- Auth: salesforceOAuth2Api
- Body (JSON): ={{
11) Upload to OneDrive
- Op: upload
- Name: ={{ $json.name }}
- Parent Folder ID: (set)
- Binary: from step 2
- Creds: OneDrive OAuth2
E
Extract from File
G
Google Drive Trigger
Message a model
Download File From Google
Update File to One Drive
Create an opportunity
Create or update an acco…
Build SOQL
Query PricebookEntries
Code in JavaScript
Create Opportunity Line …
11 nodes10 edges

How it Works

  1. 1

    Trigger

    The workflow starts with a trigger trigger.

  2. 2

    Process

    Data flows through 11 nodes, connecting code, extractfromfile, googledrive.

  3. 3

    Output

    The workflow completes its automation and delivers the result to the configured destination.

Node Details (11)

HT

HTTP Request

httpRequest

#1
GO

Google Drive

googleDrive

#2
MI

Microsoft OneDrive

microsoftOneDrive

#3
SA

Salesforce

salesforce

#4
CO

Code

code

#5
OP

OpenAI

n8n-nodes-langchain.openAi

#6

How to Import This Workflow

  1. 1Click Download JSON button on the right to save the workflow file.
  2. 2Open your n8n instance. Go to Workflows → New → Import from file.
  3. 3Select the downloaded automate-invoice-processing-with-ocr-gpt-4-salesforce-opportunity-creation file and click Import.
  4. 4Set up credentials for each service node (API keys, OAuth, etc.).
  5. 5Click Test Workflow to verify everything works, then activate it.

Or paste directly in n8n → Import from JSON:

{ "name": "Automate Invoice Processing with OCR, GPT-4 & Salesforce Opportunity Creation", "nodes": [...], ...}

Integrations

codeextractfromfilegoogledrivegoogledrivetriggerhttprequestmicrosoftonedriveopenaisalesforce

Get This Workflow

Download and import in one click

Download JSONView on n8n.io
Nodes11
Complexitymedium
Triggertrigger
Views4

Created by

Le Nguyen

Le Nguyen

@leeseifer

Tags

codeextractfromfilegoogledrivegoogledrivetriggerhttprequestmicrosoftonedriveopenaisalesforce

New to n8n?

n8n is a free, open-source workflow automation tool. Self-host it or use the cloud version.

Get n8n Free →

Related Invoice Processing Workflows

COCOEMEX+5
medium

Automate Custom QuickBooks Invoice PDFs & Email with n8n

Standard accounting templates often fail to reflect a premium brand identity. This sophisticated n8n workflow bridges the gap between financial record-keeping and professional client presentation. By moving beyond the native limitations of QuickBooks Online, this automation enables businesses to generate high-end, multi-page PDF invoices that align perfectly with their corporate styling. The process begins the moment a new invoice is generated in QuickBooks, triggering a webhook that captures real-time billing data. The workflow then utilizes advanced HTML-to-File conversion and custom Code nodes to structure data into a polished, branded layout. It handles complex logic such as line-item merging and multi-page formatting automatically. Once the document is rendered, the system bypasses generic 'no-reply' senders by routing the finalized PDF through your preferred email provider. This ensures a seamless, white-labeled experience for your clients while eliminating the manual overhead of exporting, styling, and attaching files. Ideal for agencies and service providers, this flow guarantees that your most frequent touchpoint—the bill—is as professional as your work. **Common Use Cases:** - High-end creative agencies requiring bespoke, white-labeled billing documents for premium clients. - Automated recurring subscription billing where custom tax disclosures or localized branding are required. - Service-based businesses needing to attach dynamic project reports or terms of service directly to QuickBooks invoices.

🔗 Webhook·12 nodes