{
  "name": "Organized PDF to Sheets Workflow",
  "nodes": [
    {
      "parameters": {},
      "id": "sticky-tools",
      "name": "Sticky Note - Tools",
      "type": "n8n-nodes-base.stickyNote",
      "position": [220, 20],
      "typeVersion": 1,
      "notes": "🔧 TOOLS & MODELS\nConfigured AI and integration tools"
    },
    {
      "parameters": {},
      "id": "sticky-setup",
      "name": "Sticky Note - Setup",
      "type": "n8n-nodes-base.stickyNote",
      "position": [480, 320],
      "typeVersion": 1,
      "notes": "🏗️ SHEET SETUP WORKFLOW\nCreates spreadsheet structure (runs once)"
    },
    {
      "parameters": {},
      "id": "sticky-extract",
      "name": "Sticky Note - Extract",
      "type": "n8n-nodes-base.stickyNote",
      "position": [480, 520],
      "typeVersion": 1,
      "notes": "🤖 DATA EXTRACTION WORKFLOW\nProcesses PDF pages and extracts data"
    },
    {
      "parameters": {},
      "id": "sticky-error",
      "name": "Sticky Note - Error",
      "type": "n8n-nodes-base.stickyNote",
      "position": [1120, 140],
      "typeVersion": 1,
      "notes": "⚠️ ERROR HANDLING & LOGGING\nRetry logic and result tracking"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o"
        }
      },
      "id": "openai-model",
      "name": "OpenAI Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [260, 80],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "browser-tool",
      "name": "Browser Tool",
      "type": "@n8n/n8n-nodes-langchain.toolWebScraper",
      "position": [460, 80],
      "typeVersion": 1
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "append"
      },
      "id": "sheets-tool",
      "name": "Sheets Tool",
      "type": "@n8n/n8n-nodes-langchain.toolGoogleSheets",
      "position": [660, 80],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "start-system",
      "name": "Start System",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [120, 260],
      "typeVersion": 1
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "mode-assignment",
              "name": "mode",
              "type": "string",
              "value": "extract"
            }
          ]
        },
        "options": {}
      },
      "id": "mode-selector",
      "name": "Mode Selector",
      "type": "n8n-nodes-base.set",
      "position": [340, 260],
      "typeVersion": 3.4,
      "notes": "Change mode: 'setup' or 'extract'"
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.mode }}",
              "value2": "setup"
            }
          ]
        }
      },
      "id": "setup-mode-check",
      "name": "Setup Mode?",
      "type": "n8n-nodes-base.if",
      "position": [560, 260],
      "typeVersion": 1
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "sheet-name",
              "name": "sheetName",
              "type": "string",
              "value": "Product Data"
            },
            {
              "id": "columns",
              "name": "columns",
              "type": "array",
              "value": "=['Product Name', 'Price', 'Description', 'Availability']"
            }
          ]
        },
        "options": {}
      },
      "id": "setup-config",
      "name": "Setup Config",
      "type": "n8n-nodes-base.set",
      "position": [760, 360],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "agent": "conversationalAgent",
        "promptType": "define",
        "text": "=Create a Google Sheet named '{{ $json.sheetName }}' with columns: {{ $json.columns.join(', ') }}. Return the sheet ID.",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "You are a spreadsheet setup assistant."
        }
      },
      "id": "sheet-setup-agent",
      "name": "Sheet Setup Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [980, 360],
      "typeVersion": 1.7,
      "credentials": {
        "openAiApi": {
          "id": "your-openai-cred-id",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "pdf-url",
              "name": "pdfUrl",
              "type": "string",
              "value": "https://example.com/product-catalog.pdf"
            },
            {
              "id": "sheet-id",
              "name": "sheetId",
              "type": "string",
              "value": "YOUR_SHEET_ID"
            },
            {
              "id": "retry-count",
              "name": "retryCount",
              "type": "number",
              "value": 0
            },
            {
              "id": "max-retries",
              "name": "maxRetries",
              "type": "number",
              "value": 3
            }
          ]
        },
        "options": {}
      },
      "id": "extract-config",
      "name": "Extract Config",
      "type": "n8n-nodes-base.set",
      "position": [760, 620],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineAll",
        "options": {}
      },
      "id": "split-pages",
      "name": "Split Pages",
      "type": "n8n-nodes-base.merge",
      "position": [980, 620],
      "typeVersion": 2.1,
      "notes": "Simulates page splitting - replace with actual PDF splitter"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "page-num",
              "name": "currentPage",
              "type": "number",
              "value": "={{ $itemIndex + 1 }}"
            },
            {
              "id": "page-context",
              "name": "pageContext",
              "type": "string",
              "value": "=Page {{ $itemIndex + 1 }} of PDF"
            }
          ]
        },
        "options": {}
      },
      "id": "set-page-context",
      "name": "Set Page Context",
      "type": "n8n-nodes-base.set",
      "position": [1200, 620],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "agent": "conversationalAgent",
        "promptType": "define",
        "text": "=Extract product data from {{ $json.pageContext }}. For each product found, add a row to sheet {{ $json.sheetId }} with: Product Name, Price, Description, Availability.",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "You are a data extraction assistant. Extract structured product information and save to Google Sheets."
        }
      },
      "id": "data-extraction-agent",
      "name": "Data Extraction Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [1420, 620],
      "typeVersion": 1.7,
      "credentials": {
        "openAiApi": {
          "id": "your-openai-cred-id",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.error }}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "id": "error-check",
      "name": "Error Check",
      "type": "n8n-nodes-base.if",
      "position": [1640, 620],
      "typeVersion": 1
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.retryCount }}",
              "operation": "smaller",
              "value2": "={{ $json.maxRetries }}"
            }
          ]
        }
      },
      "id": "retry-check",
      "name": "Retry Check",
      "type": "n8n-nodes-base.if",
      "position": [1640, 800],
      "typeVersion": 1
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "increment",
              "name": "retryCount",
              "type": "number",
              "value": "={{ $json.retryCount + 1 }}"
            }
          ]
        },
        "options": {}
      },
      "id": "increment-retry",
      "name": "Increment Retry",
      "type": "n8n-nodes-base.set",
      "position": [1860, 720],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_LOG_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Timestamp": "={{ $now }}",
            "Status": "Retry",
            "Page": "={{ $json.currentPage }}",
            "Attempt": "={{ $json.retryCount }}",
            "Error": "={{ $json.error }}"
          }
        },
        "options": {}
      },
      "id": "log-retry",
      "name": "Log Retry",
      "type": "n8n-nodes-base.googleSheets",
      "position": [2080, 800],
      "typeVersion": 4.5
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_LOG_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Timestamp": "={{ $now }}",
            "Status": "Max Retries Reached",
            "Page": "={{ $json.currentPage }}",
            "Attempt": "={{ $json.retryCount }}",
            "Error": "={{ $json.error }}"
          }
        },
        "options": {}
      },
      "id": "log-max-retries",
      "name": "Log Max Retries",
      "type": "n8n-nodes-base.googleSheets",
      "position": [1860, 880],
      "typeVersion": 4.5
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_LOG_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Timestamp": "={{ $now }}",
            "Status": "Success",
            "Page": "={{ $json.currentPage }}",
            "Rows_Added": "={{ $json.output }}"
          }
        },
        "options": {}
      },
      "id": "log-success",
      "name": "Log Success",
      "type": "n8n-nodes-base.googleSheets",
      "position": [1860, 540],
      "typeVersion": 4.5
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "result",
              "name": "finalResult",
              "type": "string",
              "value": "={{ $json.output }}"
            }
          ]
        },
        "options": {}
      },
      "id": "parse-output",
      "name": "Parse Output",
      "type": "n8n-nodes-base.set",
      "position": [2080, 540],
      "typeVersion": 3.4
    }
  ],
  "connections": {
    "Start System": {
      "main": [[{"node": "Mode Selector", "type": "main", "index": 0}]]
    },
    "Mode Selector": {
      "main": [[{"node": "Setup Mode?", "type": "main", "index": 0}]]
    },
    "Setup Mode?": {
      "main": [
        [{"node": "Setup Config", "type": "main", "index": 0}],
        [{"node": "Extract Config", "type": "main", "index": 0}]
      ]
    },
    "Setup Config": {
      "main": [[{"node": "Sheet Setup Agent", "type": "main", "index": 0}]]
    },
    "Sheet Setup Agent": {
      "ai_tool": [[{"node": "Sheets Tool", "type": "ai_tool", "index": 0}]],
      "ai_languageModel": [[{"node": "OpenAI Model", "type": "ai_languageModel", "index": 0}]]
    },
    "Extract Config": {
      "main": [[{"node": "Split Pages", "type": "main", "index": 0}]]
    },
    "Split Pages": {
      "main": [[{"node": "Set Page Context", "type": "main", "index": 0}]]
    },
    "Set Page Context": {
      "main": [[{"node": "Data Extraction Agent", "type": "main", "index": 0}]]
    },
    "Data Extraction Agent": {
      "main": [[{"node": "Error Check", "type": "main", "index": 0}]],
      "ai_tool": [
        [
          {"node": "Sheets Tool", "type": "ai_tool", "index": 0},
          {"node": "Browser Tool", "type": "ai_tool", "index": 0}
        ]
      ],
      "ai_languageModel": [[{"node": "OpenAI Model", "type": "ai_languageModel", "index": 0}]]
    },
    "Error Check": {
      "main": [
        [{"node": "Log Success", "type": "main", "index": 0}],
        [{"node": "Retry Check", "type": "main", "index": 0}]
      ]
    },
    "Retry Check": {
      "main": [
        [{"node": "Increment Retry", "type": "main", "index": 0}],
        [{"node": "Log Max Retries", "type": "main", "index": 0}]
      ]
    },
    "Increment Retry": {
      "main": [[{"node": "Log Retry", "type": "main", "index": 0}]]
    },
    "Log Retry": {
      "main": [[{"node": "Set Page Context", "type": "main", "index": 0}]]
    },
    "Log Success": {
      "main": [[{"node": "Parse Output", "type": "main", "index": 0}]]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 1,
  "updatedAt": "2025-11-07T00:00:00.000Z",
  "versionId": "1"
}