{
  "name": "Nodbot - Google Drive document flow with dedupe",
  "nodes": [
    {
      "parameters": {
        "path": "integration-google-drive-n8n-docflow",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "659d3713-b26e-48c7-a648-656be96ae624",
      "name": "Webhook file input",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst filename = String(src.filename ?? '').trim();\nconst mime = String(src.mime_type ?? src.mimeType ?? '').toLowerCase();\nconst size = Number(src.size_bytes ?? src.size ?? 0);\nconst entityId = String(src.entity_id ?? '').trim();\nif (!entityId) throw new Error('entity_id is required for Drive document flow');\nif (!filename) throw new Error('filename is required');\nif (size > 25 * 1024 * 1024) throw new Error(`File too large: ${size}`);\nconst allowed = ['application/pdf','image/jpeg','image/png','application/vnd.openxmlformats-officedocument.wordprocessingml.document'];\nif (!allowed.includes(mime)) throw new Error(`Unsupported MIME type: ${mime}`);\nconst safeName = filename.replace(/[\\/:*?\"<>|]+/g, '-').replace(/\\s+/g, ' ').trim();\nconst type = String(src.document_type ?? 'other').toLowerCase();\nconst folder = type === 'invoice' ? 'finance' : type === 'resume' ? 'hr' : type === 'contract' ? 'legal' : 'incoming';\nreturn [{ json: {\n  entity_id: entityId,\n  original_filename: filename,\n  safe_filename: safeName,\n  mime_type: mime,\n  size_bytes: size,\n  folder_key: folder,\n  dedupe_key: `drive:${entityId}:${safeName}:${size}`,\n  permissions: Array.isArray(src.requested_access) ? src.requested_access : []\n}}];"
      },
      "id": "b078db45-e218-44e4-b076-5783e98d2bf9",
      "name": "Validate file metadata",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "42122de4-69c7-41ec-a9e9-e7532de0e5cd",
      "name": "Check dedupe key",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "dd4dd2b5-1881-4ff0-86ee-d280a8acba28",
      "name": "Upload to Google Drive",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "af829d68-b38a-49d6-a663-b23e4444adb8",
      "name": "Set permissions",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    },
    {
      "parameters": {},
      "id": "2708b8a8-51fe-490f-96dc-51e00f9476ac",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [
        1400,
        260
      ]
    }
  ],
  "connections": {
    "Webhook file input": {
      "main": [
        [
          {
            "node": "Validate file metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate file metadata": {
      "main": [
        [
          {
            "node": "Check dedupe key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check dedupe key": {
      "main": [
        [
          {
            "node": "Upload to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Google Drive": {
      "main": [
        [
          {
            "node": "Set permissions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set permissions": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "integration",
    "production"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "1cdba42c-cf51-40fc-a9e2-15e87cd3c466",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}