{
  "id": "7SAWr8WwdGYNYLvY",
  "name": "Real-Time Parse-and-Respond",
  "tags": [],
  "nodes": [
    {
      "id": "9019a84e-beda-49ae-87f6-27794a4a5ba5",
      "name": "Send Upload Error Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        400,
        272
      ],
      "parameters": {
        "options": {
          "responseCode": 400
        },
        "respondWith": "json",
        "responseBody": "{\n     \"error\": true,\n     \"message\": \"Could not process the uploaded file. Please check the file format and try again.\"\n   }"
      },
      "typeVersion": 1.5
    },
    {
      "id": "8cd79571-85f7-4918-b96e-66caa021b7ca",
      "name": "Receive document request",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -576,
        256
      ],
      "parameters": {
        "path": "parse-document",
        "options": {
          "binaryPropertyName": "data"
        },
        "httpMethod": "POST",
        "responseMode": "responseNode",
        "authentication": "headerAuth"
      },
      "typeVersion": 2.1
    },
    {
      "id": "c9f7c4a4-8a80-42ed-b672-089d44c526d3",
      "name": "Upload Document to Parseur",
      "type": "n8n-nodes-parseur.parseur",
      "onError": "continueErrorOutput",
      "position": [
        48,
        64
      ],
      "parameters": {
        "parserId": 202635
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "e8d78f95-ef91-4521-b695-1225ca145be5",
      "name": "Parseur Trigger",
      "type": "n8n-nodes-parseur.parseurTrigger",
      "position": [
        -592,
        -416
      ],
      "parameters": {
        "parserId": 202635
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "02a1168f-1c6b-4572-b1bc-4225367057a3",
      "name": "Send Upload Success Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        400,
        96
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "={\n       \"status\": \"processing\",\n       \"documentId\": \"{{ $json.response.attachments[0].DocumentID }}\"\n     }"
      },
      "typeVersion": 1.5
    },
    {
      "id": "e59842a8-a793-47a6-afe7-94b9a712d979",
      "name": "Append row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        16,
        -400
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{ $json.Date }}",
            "Subject": "={{ $json.Subject }}",
            "Document ID": "={{ $json.DocumentID }}",
            "Sender Name": "={{ $json.SenderName }}",
            "Phone Number": "={{ $json.PhoneNumber }}",
            "Sender Email": "={{ $json.SenderEmail }}",
            "Order Reference": "={{ $json.OrderReference }}"
          },
          "schema": [
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Order Reference",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Order Reference",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone Number",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Phone Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Subject",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sender Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Document ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Document ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1xNaDfZwHV2ZRcfkyp5ka2l5sWWENFb-bmH1R-uFXcK8/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1xNaDfZwHV2ZRcfkyp5ka2l5sWWENFb-bmH1R-uFXcK8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1xNaDfZwHV2ZRcfkyp5ka2l5sWWENFb-bmH1R-uFXcK8/edit?usp=drivesdk",
          "cachedResultName": "Real Time Parse and Respond"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "79c47272-15a4-4600-afaa-3cfa029a5872",
      "name": "Check If Email Exists",
      "type": "n8n-nodes-base.if",
      "position": [
        -336,
        -384
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9856797e-9e61-4ac5-8d1b-5725d30c1290",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.SenderEmail }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "df45c8a6-de8b-49e7-92bd-70c6af438dae",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        -320,
        256
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "34fa0d1e-4c7d-47d1-9922-b85c630ab4e1",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $binary.data.mimeType }}",
              "rightValue": "pdf"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "9e0311bd-8cc2-42e1-a878-e5f921151dee",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1248,
        -528
      ],
      "parameters": {
        "width": 560,
        "height": 784,
        "content": "## Real-Time Parse-and-Respond\n### How It Works\n* **Upload Webhook:** Receives a document via POST, checks it's a PDF, and uploads it to Parseur for extraction, responding immediately with a `documentId` instead of waiting for parsing to finish.\n* **Parseur Result:** Once Parseur finishes parsing, its own trigger fires, checks the extracted data includes a sender email, and logs the result as a new row in Google Sheets.\n### Setup Checklist\n1. **Webhook:** Confirm header auth credentials on `Receive document request`, and that clients upload the file under the binary field `data`.\n2. **Parseur:** Connect Parseur credentials to both `Upload Document to Parseur` and the `Parseur Trigger` node, and confirm `parserId` (202635) matches your document template.\n3. **Google Sheets:** Verify the OAuth2 credentials, and that the target spreadsheet and sheet still match the configured document and sheet references.\n### Customization\n* **Validation:** Tighten the file check beyond \"mimeType contains pdf,\" or add a file size limit before forwarding to Parseur.\n* **Error handling:** Add a fallback path for records that fail the sender-email check instead of silently dropping them."
      },
      "typeVersion": 1
    },
    {
      "id": "5a0c0b23-570b-4c34-9fec-201c91bb8596",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -96
      ],
      "parameters": {
        "color": 7,
        "width": 1328,
        "height": 560,
        "content": "## 1. Upload Endpoint\nReceives an incoming document over webhook, validates it's a PDF, and forwards it to Parseur for parsing, responding right away with a processing status instead of waiting for extraction to finish."
      },
      "typeVersion": 1
    },
    {
      "id": "1da1eb2f-0df6-4096-b922-239bcd3d0102",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -528
      ],
      "parameters": {
        "color": 7,
        "width": 1312,
        "height": 368,
        "content": "## 2. Parsed Result Handling\nFires once Parseur completes parsing, validates the extracted sender email is present, then appends the extracted fields as a new row in Google Sheets."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "25789fa2-4ef2-4aba-8ba9-4eb7ff78a7bd",
  "nodeGroups": [],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Upload Document to Parseur",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Upload Error Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parseur Trigger": {
      "main": [
        [
          {
            "node": "Check If Email Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If Email Exists": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive document request": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Document to Parseur": {
      "main": [
        [
          {
            "node": "Send Upload Success Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Upload Error Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}