{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "cd3edd6c-a54b-4c1c-a9b5-0d9b8fb26824",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -800,
        -96
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "e96cc11a-f2c3-45fb-acdd-bd16f7eb4e76",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -576,
        -96
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.YOUR_AWS_SECRET_KEY_HERE_JdBR0J2M3ydLhkwlnlChh4/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1MeQdveFXA4ihTc7FrFyl_JdBR0J2M3ydLhkwlnlChh4",
          "cachedResultUrl": "https://docs.google.YOUR_AWS_SECRET_KEY_HERE_JdBR0J2M3ydLhkwlnlChh4/edit?usp=drivesdk",
          "cachedResultName": "linkedin profiles"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "69d5390c-fbb4-497f-b1e3-17ca778343af",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -352,
        -96
      ],
      "parameters": {
        "text": "=you have to identify the domain of the company from provided data.\nif domain is not provided then make a search term that help me find the domain which should end with \"official site\"\nmake value \"null\" if not available\ndon't hellucinate or make assumptions\nstrictly output in this json format\n{\n  \"domain\": \"company-domain/null\",\n  \"search term\": \"search-term/null\"\n}\n\ndata:\n name:{{ $json.name }}\n position:{{ $json.position }}\n description:{{ $json.description }}",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2,
      "alwaysOutputData": false
    },
    {
      "id": "3cdadbca-84da-4563-aef8-5c7c5e7a2937",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -288,
        128
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "705066c1-98cf-4f32-9071-663157062e14",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        0,
        -96
      ],
      "parameters": {
        "jsCode": "// Get input array\nconst itemsList = items;\n\n// Convert each wrapped JSON string into a usable object\nconst cleaned = itemsList.map(item => {\n  let raw = item.json.output;\n\n  // Remove ```json block formatting\n  raw = raw.replace(/```json|```/g, \"\").trim();\n\n  // Parse to actual JSON\n  const data = JSON.parse(raw);\n\n  return { json: data };\n});\n\n// Return cleaned objects\nreturn cleaned;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "645704a6-c18d-43d0-b613-42de5905d747",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        224,
        -96
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "domain",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "47061173-9c15-44c8-9678-a15b691cefe8",
                    "operator": {
                      "type": "string",
                      "operation": "notEquals"
                    },
                    "leftValue": "={{ $json.domain }}",
                    "rightValue": "=null"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "no domain",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "2d15a11e-14e1-4c30-b7b8-c561df025d04",
                    "operator": {
                      "type": "string",
                      "operation": "notEquals"
                    },
                    "leftValue": "={{ $json[\"search term\"] }}",
                    "rightValue": "=null"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "9fab98ab-0c8d-4e0b-8f07-55cf6d84490a",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        448,
        -400
      ],
      "parameters": {
        "url": "https://api.hunter.io/v2/email-finder?",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "domain",
              "value": "={{ $json.domain }}"
            },
            {
              "name": "first_name",
              "value": "={{ $('Get row(s) in sheet').item.json.name }}"
            },
            {
              "name": "last_name",
              "value": "={{ $('Get row(s) in sheet').item.json.name }}"
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "2c4e51f0-7769-47c1-bb59-0b1800d4ae65",
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        400,
        208
      ],
      "parameters": {
        "url": "https://www.googleapis.com/customsearch/v1",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "cx",
              "value": "c0fa13214e7ee42a4"
            },
            {
              "name": "q",
              "value": "={{ $json[\"search term\"] }}"
            }
          ]
        }
      },
      "credentials": {
        "httpBasicAuth": {
          "name": "<your credential>"
        },
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "af042f70-b402-48d9-a432-0cb026400e36",
      "name": "Append or update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        672,
        -400
      ],
      "parameters": {
        "columns": {
          "value": {
            "name": "={{ $('Get row(s) in sheet').item.json.name }}",
            "email": "={{ $json.data.email }}",
            "domain": "={{ $json.data.domain }}"
          },
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "position",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "position",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "profile links",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "profile links",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "description",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "img link",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "img link",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "domain",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "domain",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "searched position",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "searched position",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "searched industry",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "searched industry",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "searched region",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "searched region",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "name"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.YOUR_AWS_SECRET_KEY_HERE_JdBR0J2M3ydLhkwlnlChh4/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1MeQdveFXA4ihTc7FrFyl_JdBR0J2M3ydLhkwlnlChh4",
          "cachedResultUrl": "https://docs.google.YOUR_AWS_SECRET_KEY_HERE_JdBR0J2M3ydLhkwlnlChh4/edit?usp=drivesdk",
          "cachedResultName": "linkedin profiles"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "441c3f68-d279-4fb5-a6fb-f64483d94950",
      "name": "HTTP Request2",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1424,
        208
      ],
      "parameters": {
        "url": "https://api.hunter.io/v2/email-finder?",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "domain",
              "value": "={{ $json.domain }}"
            },
            {
              "name": "first_name",
              "value": "={{ $('Get row(s) in sheet').item.json.name }}"
            },
            {
              "name": "last_name",
              "value": "={{ $('Get row(s) in sheet').item.json.name }}"
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "9a746e3d-5481-472d-aa35-944f8c0701be",
      "name": "Code in JavaScript1",
      "type": "n8n-nodes-base.code",
      "disabled": true,
      "position": [
        624,
        208
      ],
      "parameters": {
        "jsCode": "// n8n Code/Function node - extract cleaned domains from various input shapes\n\nfunction addFromUrlString(urlStr, domainSet) {\n  if (!urlStr || typeof urlStr !== 'string') return;\n  urlStr = urlStr.trim();\n  urlStr = urlStr.replace(/<[^>]*>/g, ''); // remove HTML tags\n  try {\n    const u = urlStr.startsWith('http://') || urlStr.startsWith('https://')\n      ? new URL(urlStr)\n      : new URL('https://' + urlStr);\n    let host = u.hostname.toLowerCase();\n    if (host.startsWith('www.')) host = host.slice(4);\n    if (host) domainSet.add(host);\n  } catch (e) {\n    const m = urlStr.match(/([a-z0-9.-]+\\.[a-z]{2,})(\\/|$)/i);\n    if (m && m[1]) {\n      let host = m[1].toLowerCase();\n      if (host.startsWith('www.')) host = host.slice(4);\n      domainSet.add(host);\n    }\n  }\n}\n\nfunction processEntry(entry, domainSet) {\n  if (!entry || typeof entry !== 'object') return;\n  if (entry.link) addFromUrlString(entry.link, domainSet);\n  if (entry.formattedUrl) addFromUrlString(entry.formattedUrl, domainSet);\n  if (entry.displayLink) addFromUrlString(entry.displayLink, domainSet);\n\n  if (Array.isArray(entry.items)) {\n    entry.items.forEach(it => {\n      if (it.link) addFromUrlString(it.link, domainSet);\n      if (it.formattedUrl) addFromUrlString(it.formattedUrl, domainSet);\n      if (it.displayLink) addFromUrlString(it.displayLink, domainSet);\n    });\n  }\n}\n\n// MAIN: iterate over each incoming n8n item\nreturn items.map(item => {\n  const domains = new Set();\n  const j = item.json;\n\n  if (Array.isArray(j.data)) {\n    j.data.forEach(obj => processEntry(obj, domains));\n  } else if (Array.isArray(j.items)) {\n    j.items.forEach(obj => processEntry(obj, domains));\n  } else if (j.link || j.displayLink || j.formattedUrl) {\n    processEntry(j, domains);\n  } else if (Array.isArray(j)) {\n    j.forEach(obj => processEntry(obj, domains));\n  } else {\n    Object.keys(j || {}).forEach(k => {\n      const v = j[k];\n      if (Array.isArray(v)) v.forEach(obj => processEntry(obj, domains));\n    });\n  }\n\n  // return one item per original input item\n  return { json: { domains: Array.from(domains) } };\n});\n\n"
      },
      "typeVersion": 2
    },
    {
      "id": "96fb1bbb-c9ac-4707-ac0b-7508c5028e3d",
      "name": "AI Agent1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        848,
        208
      ],
      "parameters": {
        "text": "=you have to simple matching and finding task where i will give a search term and list of domain you have to find the read domain from that \n\nstrictly output in json\n{\n  \"domain\": \"domain\"\n}\n\nsearch term:  {{ $('Switch').item.json[\"search term\"] }}\nlist of domains: {{ $json.domains }}",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "96d35781-3750-4a4e-8112-897681c92798",
      "name": "Google Gemini Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        928,
        432
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "89a7aaff-1c2e-4e1b-b37c-de1869ed13a3",
      "name": "Code in JavaScript2",
      "type": "n8n-nodes-base.code",
      "position": [
        1200,
        208
      ],
      "parameters": {
        "jsCode": "// Get input array\nconst itemsList = items;\n\n// Convert each wrapped JSON string into a usable object\nconst cleaned = itemsList.map(item => {\n  let raw = item.json.output;\n\n  // Remove ```json block formatting\n  raw = raw.replace(/```json|```/g, \"\").trim();\n\n  // Parse to actual JSON\n  const data = JSON.parse(raw);\n\n  return { json: data };\n});\n\n// Return cleaned objects\nreturn cleaned;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "3787b1f4-eceb-4eea-866c-58b508ad5df7",
      "name": "Append or update row in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1648,
        208
      ],
      "parameters": {
        "columns": {
          "value": {
            "name": "={{ $('Get row(s) in sheet').item.json.name }}",
            "email": "={{ $json.data.email }}",
            "domain": "={{ $json.data.domain }}"
          },
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "position",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "position",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "profile links",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "profile links",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "description",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "img link",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "img link",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "domain",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "domain",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "searched position",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "searched position",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "searched industry",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "searched industry",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "searched region",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "searched region",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "name"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.YOUR_AWS_SECRET_KEY_HERE_JdBR0J2M3ydLhkwlnlChh4/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1MeQdveFXA4ihTc7FrFyl_JdBR0J2M3ydLhkwlnlChh4",
          "cachedResultUrl": "https://docs.google.YOUR_AWS_SECRET_KEY_HERE_JdBR0J2M3ydLhkwlnlChh4/edit?usp=drivesdk",
          "cachedResultName": "linkedin profiles"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "b7c76f06-879b-46e4-9bfe-fb1327c9fa79",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1632,
        -272
      ],
      "parameters": {
        "width": 704,
        "height": 464,
        "content": "## Automated Email Finder form linkedin profile\n### How it works\n1.  Reads contact data, including name, position, and description, from a specified Google Sheet.\n2.  An AI agent analyzes this data to identify the company domain or create a targeted search term if the domain is not provided.\n3.  If a domain is identified, the workflow uses Hunter.io to find the corresponding email address.\n4.  If no domain is initially found, it performs a Google Custom Search to retrieve relevant web results. Another AI agent then extracts the most accurate company domain from these results.\n5.  Finally, the workflow updates the original Google Sheet with the found email address and company domain for each contact.\n### Setup\n- [ ] Connect your Google Sheets account.\n- [ ] Specify the Google Sheet document ID and the exact sheet name.\n- [ ] Add your Google Gemini (PaLM) API key to the \\\"Google Gemini Chat Model\\\" nodes.\n- [ ] Add your Hunter.io API key to the \\\"HTTP Request\\\" nodes.\n- [ ] Add your Google Custom Search API key and Custom Search Engine ID (CX) to the \\\"HTTP Request1\\\" node."
      },
      "typeVersion": 1
    },
    {
      "id": "3b6932d5-1fb3-4f7e-8c3b-9d41760a0547",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        -192
      ],
      "parameters": {
        "color": 7,
        "width": 992,
        "height": 464,
        "content": "## 1. get sheet data and check for domain is provided"
      },
      "typeVersion": 1
    },
    {
      "id": "1f3edf5c-2d07-4f66-8521-7e7f6ea7b564",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        192,
        -464
      ],
      "parameters": {
        "color": 7,
        "width": 768,
        "height": 528,
        "content": "## 2. if domain exists find mail from hunter.io and update google sheets"
      },
      "typeVersion": 1
    },
    {
      "id": "7eedf9c3-2472-4a41-aaac-6077e274761e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        112
      ],
      "parameters": {
        "color": 7,
        "width": 1440,
        "height": 448,
        "content": "## 3. search for domain and find the mail to update sheets\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "Code in JavaScript2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Code in JavaScript1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request2": {
      "main": [
        [
          {
            "node": "Append or update row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript1": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript2": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}