{
  "name": "Keencrest: Google Sheets domains to emails (Apify)",
  "nodes": [
    {
      "parameters": {},
      "id": "b1200000-0000-4000-8000-000000000001",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "",
          "mode": "name"
        },
        "options": {}
      },
      "id": "b1200000-0000-4000-8000-000000000002",
      "name": "Read Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        220,
        0
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "",
          "name": "Google Sheets account"
        }
      },
      "notes": "Pick your spreadsheet and tab. Needs a column named website (header in row 1) and empty columns email and status.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "jsCode": "// One item per sheet row. Adds a clean \"domain\" key, the form the Actor returns.\nconst out = [];\nfor (const item of $input.all()) {\n  const raw = String(item.json.website || '').trim();\n  if (!raw) continue;\n  const domain = raw.replace(/^https?:\\/\\//i, '').replace(/^www\\./i, '').split('/')[0].toLowerCase();\n  out.push({ json: { ...item.json, domain } });\n}\nreturn out;"
      },
      "id": "b1200000-0000-4000-8000-000000000003",
      "name": "Normalize domains",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Gather every domain into ONE request body (the Actor runs the whole list in one call).\n// Keep batches to about 100-200 sites per run; split longer sheets.\nconst domains = [...new Set($input.all().map(i => i.json.domain))];\nreturn [{ json: { websites: domains, maxPagesPerSite: 4 } }];"
      },
      "id": "b1200000-0000-4000-8000-000000000004",
      "name": "Build request body",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/datagleaner~website-contact-details-scraper/run-sync-get-dataset-items?maxTotalChargeUsd=1&fields=domain,bestEmail,status,failureReason",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}",
        "options": {
          "timeout": 300000
        }
      },
      "id": "b1200000-0000-4000-8000-000000000005",
      "name": "Apify run-sync",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Apify token (Authorization: Bearer ...)"
        }
      },
      "notes": "Create a Header Auth credential: Name = Authorization, Value = Bearer YOUR_APIFY_TOKEN. maxTotalChargeUsd=1 caps spend per run.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByFields",
        "fieldsToMatchString": "domain",
        "joinMode": "keepEverything",
        "options": {}
      },
      "id": "b1200000-0000-4000-8000-000000000006",
      "name": "Join on domain",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        1100,
        100
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "website": "={{ $json.website }}",
            "email": "={{ $json.bestEmail || '' }}",
            "status": "={{ $json.status || 'missing' }}"
          },
          "matchingColumns": [
            "website"
          ],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "b1200000-0000-4000-8000-000000000007",
      "name": "Write back to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1320,
        100
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "",
          "name": "Google Sheets account"
        }
      },
      "notes": "Select the same spreadsheet and tab. Rows are matched on the website column, never by position.",
      "notesInFlow": true
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Read Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Sheet": {
      "main": [
        [
          {
            "node": "Normalize domains",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize domains": {
      "main": [
        [
          {
            "node": "Build request body",
            "type": "main",
            "index": 0
          },
          {
            "node": "Join on domain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build request body": {
      "main": [
        [
          {
            "node": "Apify run-sync",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apify run-sync": {
      "main": [
        [
          {
            "node": "Join on domain",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Join on domain": {
      "main": [
        [
          {
            "node": "Write back to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}