{
  "name": "Automate invoice processing with OCR, GPT-4 & Salesforce opportunity creation",
  "nodes": [
    {
      "id": "c87ed7b7-b77d-4236-999e-afefe9064033",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2640,
        -656
      ],
      "parameters": {
        "width": 464,
        "height": 912,
        "content": "# PDF Invoice Extractor (AI) to Salesforce Opportunity\n\nWhat it does:\nWatch a Drive folder → OCR PDF → extract invoices (JSON) via LLM → mirror file to OneDrive → upsert Buyer to Salesforce → create O"
      }
    },
    {
      "id": "e7665458-f2f8-4ad1-b318-1fbe4e3ff464",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -1456,
        -144
      ]
    },
    {
      "id": "1a593bd5-922f-4f0d-9ddb-0220ed3be3cb",
      "name": "Google Drive Trigger",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        -1952,
        -144
      ]
    },
    {
      "id": "ce439fd0-ffcf-4891-a861-61fa62e57a38",
      "name": "Message a model",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -1264,
        -144
      ]
    },
    {
      "id": "053cdfcf-65f6-4ec6-90fa-090a08da31c8",
      "name": "Download File From Google",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -1712,
        -144
      ]
    },
    {
      "id": "157f5cdc-de47-4f90-96ea-202636ac5016",
      "name": "Update File to One Drive",
      "type": "n8n-nodes-base.microsoftOneDrive",
      "position": [
        -1424,
        32
      ]
    },
    {
      "id": "80f186d6-499e-4da2-a49e-a503de546be4",
      "name": "Create an opportunity",
      "type": "n8n-nodes-base.salesforce",
      "position": [
        -656,
        -144
      ]
    },
    {
      "id": "9f06013f-ff72-4f08-b72e-4b42931f393f",
      "name": "Create or update an account",
      "type": "n8n-nodes-base.salesforce",
      "position": [
        -928,
        -144
      ]
    },
    {
      "id": "70336cbd-460f-4396-964c-196baf054d8f",
      "name": "Build SOQL",
      "type": "n8n-nodes-base.code",
      "position": [
        -352,
        -144
      ]
    },
    {
      "id": "021cd4c3-82b4-4589-a523-bea9bd18ae11",
      "name": "Query PricebookEntries",
      "type": "n8n-nodes-base.salesforce",
      "position": [
        -64,
        -144
      ]
    },
    {
      "id": "cafe3e46-af7a-44eb-87b2-9fb34f7cb96b",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        240,
        -144
      ]
    },
    {
      "id": "22eb1f99-b562-4160-bf89-6b0dd890a308",
      "name": "Create Opportunity Line Items",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        576,
        -144
      ]
    },
    {
      "id": "39ef7a5e-6825-4583-b9d2-dbc534bb7c5c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2048,
        -448
      ],
      "parameters": {
        "width": 256,
        "height": 272,
        "content": "## 1) Google Drive Trigger\n- Op: fileCreated in folder (ID)\n- Poll: every minute\n- Creds: Google Drive OAuth2\n- Note: Ensure access/Shared Drive rights"
      }
    },
    {
      "id": "99e69d7e-2ad1-40ef-b476-5ae869e5f927",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1776,
        -448
      ],
      "parameters": {
        "width": null,
        "height": 272,
        "content": "## 2) Download from Drive\n- Op: download by {{$json.id}}\n- Binary key: data (default)\n- Creds: Google Drive OAuth2"
      }
    },
    {
      "id": "0830b83e-19f5-489e-a9bd-1eb3e1f7e50b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1520,
        -448
      ],
      "parameters": {
        "width": 224,
        "height": 272,
        "content": "## 3) Extract from File\n- Op: pdf (enable OCR for scans)\n- Output: {{$json.text}}"
      }
    },
    {
      "id": "edb057fe-1446-4aec-929b-7022c9704ee1",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        -512
      ],
      "parameters": {
        "width": 256,
        "height": 352,
        "content": "## 4) Message a Model (JSON)\n- Node: @n8n/n8n-nodes-langchain.openAi\n- Model: gpt-4.1 (or gpt-4.1-mini)\n- Prompt: strict schema; **return only JSON array**\n- jsonOutput: true\n- Output path (first item"
      }
    },
    {
      "id": "4f193f7a-2f69-4eb3-9ee6-e15bd50236d3",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1008,
        -512
      ],
      "parameters": {
        "width": null,
        "height": 352,
        "content": "## 5) Salesforce: Upsert Account (Buyer)\n- Node: salesforce (account upsert)\n- External Id: tax_id__c\n- externalIdValue: ={{ $json.message.content.buyer.tax_id }}\n- name: ={{ $json.message.content.buy"
      }
    },
    {
      "id": "12811762-358e-4cb7-aec6-92f9f93d47ae",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        -576
      ],
      "parameters": {
        "width": 304,
        "height": 416,
        "content": "## 6) Salesforce: Create Opportunity\n- Node: salesforce (resource: opportunity)\n- name: ={{ $('Message a model').item.json.message.content.invoice.code }}\n- closeDate: ={{ $('Message a model').item.js"
      }
    },
    {
      "id": "0c2e625e-0062-480f-b394-45ea687db779",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        -384
      ],
      "parameters": {
        "width": 288,
        "height": 224,
        "content": "## 7) Code: Build SOQL (PricebookEntry)\n- Node: Code (JS)\n- Purpose: collect ProductCodes from LLM products → build SOQL for PricebookEntry by Pricebook2Id\n- Output: { soql, codes }"
      }
    },
    {
      "id": "9b390d82-6233-4d6f-b606-64efadddd654",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        -352
      ],
      "parameters": {
        "width": null,
        "height": 192,
        "content": "## 8) Salesforce: Query PricebookEntries\n- Node: salesforce (search)\n- query: ={{ $json.soql }}"
      }
    },
    {
      "id": "b4ca0bf1-925c-40c6-ba35-208e70a63be1",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        -528
      ],
      "parameters": {
        "width": 320,
        "height": 368,
        "content": "## 9) Code: Build OLI Payloads\n- Node: Code (JS)\n- Inputs: \n  - OpportunityId: ={{ $('Create an opportunity').first().json.id }}\n  - Lines: ={{ $('Message a model').first().json.message.content.produc"
      }
    },
    {
      "id": "0d8dcf4b-77d7-439f-b345-f0fcec555b01",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        -464
      ],
      "parameters": {
        "width": 272,
        "height": 272,
        "content": "## 10) HTTP Request: Create Opportunity Line Items\n- Method: POST\n- URL: https://<your-instance>.my.salesforce.com/services/data/v65.0/composite/sobjects\n- Auth: salesforceOAuth2Api\n- Body (JSON): ={{"
      }
    },
    {
      "id": "73d319ea-e10d-4f10-8132-63976a3cfacf",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1488,
        176
      ],
      "parameters": {
        "width": null,
        "height": 272,
        "content": "## 11) Upload to OneDrive\n- Op: upload\n- Name: ={{ $json.name }}\n- Parent Folder ID: (set)\n- Binary: from step 2\n- Creds: OneDrive OAuth2"
      }
    }
  ],
  "connections": {
    "Build SOQL": {
      "main": [
        [
          {
            "node": "Query PricebookEntries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Create or update an account",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Create Opportunity Line Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive Trigger": {
      "main": [
        [
          {
            "node": "Download File From Google",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create an opportunity": {
      "main": [
        [
          {
            "node": "Build SOQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query PricebookEntries": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File From Google": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          },
          {
            "node": "Update File to One Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create or update an account": {
      "main": [
        [
          {
            "node": "Create an opportunity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Opportunity Line Items": {
      "main": [
        []
      ]
    }
  }
}