Automated Invoice OCR Processing and Salesforce Opportunity Creation - n8n Workflow

Use this powerful n8n workflow to automatically process PDF invoices using GPT-4 for data extraction, creating corresponding Accounts, Opportunities, and Line Items in Salesforce.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

• Sales Operations teams needing to automate B2B invoice processing.
• Financial controllers seeking to log incoming supplier or client invoices directly into their CRM.
• n8n users looking for advanced examples combining OCR, GPT-4 integration, and complex CRM API operations.
• Developers needing reliable, structured data extraction using an n8n template.

Overview

Manually translating PDF invoices into actionable sales data is slow and error-prone. This robust n8n workflow solves that challenge by providing an end-to-end automation solution. It utilizes an n8n trigger to monitor file uploads, employs OCR technology, and leverages GPT-4 via the 'Message a model' n8n node to perform meticulous data extraction based on a strict schema. The subsequent steps integrate deeply with Salesforce, ensuring that extracted Buyer information leads to an Account Upsert, followed by the creation of a detailed Sales Opportunity and associated Opportunity Line Items (OLIs) derived from your Pricebook Entries. This complete n8n node sequence ensures accurate, fast, and scalable financial data integration.

How it Works

This automation starts with a file creation event and performs complex data manipulation and CRM synchronization.


  1. The Google Drive n8n trigger initiates the n8n workflow when a new PDF invoice is detected in the monitored folder.

  2. The file is downloaded, and the Extract from File n8n node processes the PDF, performing OCR if necessary, to yield raw text.

  3. The raw text is fed to the Message a model n8n node, which uses a GPT-4 instruction set to strictly output a normalized JSON array containing all buyer, invoice, and product line details.

  4. A Salesforce n8n node uses the extracted buyer's tax ID to Upsert (create or update) the corresponding Account record.

  5. The next Salesforce n8n node creates a new Opportunity, linking it to the Account ID generated in the previous step and using the extracted Grand Total and Issue Date.

  6. The Build SOQL Code n8n node collects all product names from the LLM output and generates a precise SOQL query string to look up their matching PricebookEntry IDs within Salesforce.

  7. The Query PricebookEntries Salesforce n8n node executes this query.

  8. The Code in JavaScript n8n node aggregates the newly created Opportunity ID, the original product line data, and the retrieved PricebookEntry IDs to construct a bulk payload for Opportunity Line Item creation.

  9. The Create Opportunity Line Items HTTP Request n8n node posts this payload to the Salesforce Composite API, finalizing the Opportunity.

  10. Finally, the Update File to One Drive n8n node archives the original PDF file for record-keeping. This comprehensive n8n workflow provides a powerful integration backbone.

Installation Guide


  1. Import the n8n workflow: Copy the provided JSON data and import it into your n8n instance.

  2. Google Drive Credentials: Set up credentials for the Google Drive Trigger and Download File From Google n8n node.

  3. OpenAI Credentials: Configure your OpenAI API key for the 'Message a model' n8n node. Ensure your API key supports the specified model (GPT-4.1 or similar).

  4. Salesforce Credentials: Establish OAuth2 credentials for Salesforce. These are required for the Upsert Account, Create Opportunity, Query PricebookEntries, and Create Opportunity Line Items n8n nodes.

  5. Hardcoded IDs:

- In the Google Drive Trigger n8n trigger, update the folderToWatch ID to your desired incoming folder.
- In the Build SOQL Code n8n node, update the pricebook2Id variable to your active Salesforce Pricebook ID (01sxxxxxxxxxxxxxxx).
- In the Update File to One Drive n8n node, replace folderidonedrive with your target OneDrive folder ID.
- In the Create Opportunity Line Items HTTP Request n8n node, update the URL to your correct Salesforce domain (https://mydomain.salesforce.com).

  1. Activate the n8n workflow: Set the n8n trigger to 'Active' to start monitoring for new invoices.

Node Details

This n8n template relies on several key n8n node configurations:

Google Drive Trigger (n8n trigger):
Function: Starts the n8n workflow when a new file is created in a specific monitored folder.
Key Configuration: event: fileCreated, triggerOn: specificFolder, using a specific folder ID.
Extract from File (n8n node):
Function: Processes the downloaded PDF binary data, yielding text output. Essential for OCR on scanned invoices.
Key Configuration: operation: pdf (Assumes internal OCR is enabled or available).
Message a model (OpenAI n8n node):
Function: Uses GPT-4 for complex structured data extraction from the raw invoice text into a predictable JSON format.
Key Configuration: modelId: gpt-4.1, jsonOutput: true, utilizes a highly detailed system prompt for schema enforcement and normalization.
Create or update an account (Salesforce n8n node):
Function: Manages Account records in Salesforce. It performs an upsert based on the buyer's Tax ID (mapped to a custom external ID field taxidc).
Create an opportunity (Salesforce n8n node):
Function: Creates the Opportunity record, linking it to the Account ID from the previous step and mapping key extracted fields like grandtotal and issue_date.
Build SOQL (Code n8n node):
Function: A crucial n8n node that dynamically constructs a SOQL query to fetch the necessary PricebookEntry IDs required for creating line items.
Key Configuration: Hardcoded pricebook2Id and dynamic generation of an IN clause using product names from the LLM output.
Code in JavaScript (Code n8n node):
Function: Maps the LLM product lines to the corresponding PricebookEntry IDs retrieved from Salesforce, preparing the final payload structure for the Salesforce Composite API.
Create Opportunity Line Items (HTTP Request n8n node):
Function: Uses the Salesforce Composite API for efficient bulk creation of the Opportunity Line Items.
* Key Configuration: method: POST, utilizes the predefined Salesforce credential for authentication, sends the mapped JSON payload.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by

Salesforce Architect with 10+ years of experience in CRM, integrations, and automation. Skilled in Apex, LWC, REST APIs, and full-stack dev (JavaScript, .NET). I build secure, scalable workflows in n8n—connecting Salesforce, Stripe, and more. Passionate about lead scoring, data sync, and secure field masking. Certified Application Architect with deep expertise in platform, integration, and data architecture.

Featured*