{
  "id": "cfU9qIsbNcDtvXqy",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Scrape B2B leads from Apollo, generate AI cold emails and send via Gmail",
  "tags": [],
  "nodes": [
    {
      "id": "7d7490a0-d44e-44f2-a794-81f581707b34",
      "name": "Parse Email JSON",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        2144,
        864
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"Email Subject\": \"your subject here\",\n  \"Email Body\": \"your email body here\"\n} "
      },
      "typeVersion": 1.3
    },
    {
      "id": "c1483978-9b8c-4dfa-b224-b3faf673e708",
      "name": "Filter Pending Leads",
      "type": "n8n-nodes-base.if",
      "onError": "continueRegularOutput",
      "position": [
        1552,
        704
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "4957b200-c677-4722-b96f-2bb208aaff56",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $('Fetch Leads from Sheet').item.json['Email Address '] }}",
              "rightValue": ""
            },
            {
              "id": "de81c4ac-4327-4102-b59a-c70691efad04",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Fetch Leads from Sheet').item.json['Outreach Status '] }}",
              "rightValue": "Pending"
            }
          ]
        }
      },
      "retryOnFail": false,
      "typeVersion": 2.3
    },
    {
      "id": "3dde7c70-e762-4b8c-ab2c-d21b858c54e9",
      "name": "AI Cold Email Writer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2000,
        656
      ],
      "parameters": {
        "text": "=You are an expert B2B cold email copywriter for [COMPANY NAME].\n\nABOUT [COMPANY NAME]:\n- Describe your services here\n- Add your unique value proposition\n- Add your website URL\n- Add your contact number\n\nEMAIL RULES:\n- NEVER use \"I hope this email finds you well\"\n- NEVER mention pricing\n- NEVER use more than 4 paragraphs\n- Sound professional, warm and human\n\nOUTPUT RULES:\n- Output ONLY a raw valid JSON object\n- No markdown, no backticks\n{\n  \"Email Subject\": \"subject line here\",\n  \"Email Body\": \"full email body here\"\n}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "59dab260-3e2c-48d0-be54-f5c823d25e1b",
      "name": "Groq LLM (Fast AI)",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        2000,
        864
      ],
      "parameters": {
        "model": "qwen/qwen3-32b",
        "options": {}
      },
      "credentials": {
        "groqApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "79a4f3fc-0a6d-4a6c-b86c-b713052a5866",
      "name": "Save Email to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2352,
        656
      ],
      "parameters": {
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "YOUR_GOOGLE_SHEET_URL_HERE"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "5db70332-f89a-4dfd-a41c-f0376c4a3784",
      "name": "Apollo \u2014 Search Leads",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -320,
        1328
      ],
      "parameters": {
        "url": "https://api.apollo.io/api/v1/mixed_people/api_search",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"person_titles\": [\"{{ $json['Job Title'] }}\"],\n  \"person_locations\": [\"{{ $json.Location }}\"],\n  \"per_page\": \"{{ $json['Number of Leads'] }}\",\n  \"page\": 1\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "cfbd6839-323b-425a-8a6f-654c388b172a",
      "name": "Apollo \u2014 Enrich Lead Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1808,
        1280
      ],
      "parameters": {
        "url": "https://api.apollo.io/api/v1/people/bulk_match",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"details\": [\n    { \"id\": \"{{ $('Deduplicate Leads').first().json.id }}\" }\n  ],\n  \"reveal_personal_emails\": true,\n  \"reveal_phone_number\": false\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "d0e5d3d8-9800-4a72-9600-3beb170208fc",
      "name": "Format & Clean Lead Data",
      "type": "n8n-nodes-base.code",
      "position": [
        2032,
        1280
      ],
      "parameters": {
        "jsCode": "const matches = $input.first().json.matches || [];\nfunction titleCase(str) {\n  return (str || \"\").split(\" \")\n    .map(w => w.charAt(0).toUpperCase() + w.slice(1))\n    .join(\" \");\n}\nfunction getIndustry(org, enriched) {\n  const raw = org.industry || enriched.industry || \"\";\n  const kws = org.keywords || enriched.keywords || [];\n  const firstKw = kws[0] || \"\";\n  let label = \"\";\n  if (raw && firstKw) {\n    label = firstKw.length < raw.length ? firstKw : raw;\n  } else {\n    label = raw || firstKw;\n  }\n  return titleCase(label);\n}\nconst outputItems = [];\nfor (const enriched of matches) {\n  const org = enriched.organization || {};\n  const full_name =\n    `${enriched.first_name || \"\"} ${enriched.last_name_unobfuscated || enriched.last_name || \"\"}`.trim() ||\n    enriched.name ||\n    \"\";\n  const rawTitle = enriched.title || \"\";\n  const job_title = [...new Set(rawTitle.split(\",\").map(t => t.trim()))][0] || \"\";\n  let phone = \"\";\n  const phoneNumbers = enriched.phone_numbers || [];\n  if (phoneNumbers.length) {\n    const preferred = phoneNumbers.find(p =>\n      [\"work\", \"direct\", \"work_hq\"].includes(p.type)\n    );\n    phone = preferred?.sanitized_number || phoneNumbers[0]?.sanitized_number || \"\";\n  }\n  if (!phone) {\n    phone = org.phone || org.primary_phone?.number || \"\";\n  }\n  if (phone && !phone.startsWith(\"*\")) {\n    phone = \"'\" + phone;\n  } else {\n    phone = \"\";\n  }\n  let linkedin = enriched.linkedin_url || \"\";\n  if (linkedin && !linkedin.startsWith(\"http\")) {\n    linkedin = \"https://linkedin.com\" + linkedin;\n  }\n  const record = {\n    \"Apollo ID\":       enriched.id || \"\",\n    \"Full Name\":       full_name,\n    \"Job Title\":       job_title,\n    \"Company\":         org.name || \"\",\n    \"Email Address\":   enriched.email || \"\",\n    \"Phone Number\":    phone,\n    \"Profile URL\":     linkedin,\n    \"Company Website\": org.website_url || \"\",\n    \"Industry Genre\":  getIndustry(org, enriched),\n  };\n  for (const key of Object.keys(record)) {\n    if (!record[key]) record[key] = \"\";\n  }\n  outputItems.push({ json: record });\n}\nreturn outputItems;"
      },
      "typeVersion": 2
    },
    {
      "id": "f67ebebf-3686-4b51-b99f-d31305d3103f",
      "name": "Save Leads to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2256,
        1360
      ],
      "parameters": {
        "columns": {
          "value": {
            "Company": "={{ $json.Company }}",
            "Apollo ID": "={{ $json['Apollo ID'] }}",
            "Job Title": "={{ $json['Job Title'] }}",
            "Full Name ": "={{ $json['Full Name'] }}",
            "Phone Number": "={{ $json['Phone Number'] }}",
            "Profile URL ": "={{ $json['Profile URL'] }}",
            "Email Address ": "={{ $json['Email Address'] }}",
            "Company Website": "={{ $json['Company Website'] }}",
            "Industry Genre ": "={{ $json['Industry Genre'] }}",
            "Outreach Status ": "Pending"
          },
          "schema": [
            {
              "id": "Apollo ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Apollo ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Full Name ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Full Name ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Job Title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Job Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email Address ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email Address ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone Number",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Profile URL ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Profile URL ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Website",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company Website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Industry Genre ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Industry Genre ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email Subject ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email Subject ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email Body",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email Body",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Outreach Status ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Outreach Status ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Apollo ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Master Sheet"
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "YOUR_GOOGLE_SHEET_URL_HERE"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "04b41b53-8a87-4c59-a904-96a7f0a091ef",
      "name": "Fetch Leads from Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1328,
        704
      ],
      "parameters": {
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "YOUR_GOOGLE_SHEET_URL_HERE"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "2cbc42cd-ac15-4d44-9c44-256fc2ad46cd",
      "name": "Extract People Data",
      "type": "n8n-nodes-base.code",
      "position": [
        -96,
        1328
      ],
      "parameters": {
        "jsCode": "const people = $input.first().json.people || [];\nconst jobTitle = $('Lead Generation Form').first().json['Job Title'] || '';\n\nreturn people.map(person => {\n  return {\n    json: {\n      id: person.id,\n      person: person,\n      designation: jobTitle\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "1345a443-3a7c-47a3-a0d2-a83665a24883",
      "name": "Skip Duplicates",
      "type": "n8n-nodes-base.if",
      "position": [
        1296,
        1280
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "426c1abb-5c0c-4b6b-91a1-0c0fef805dcb",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.isDuplicate }}",
              "rightValue": false
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "fffee28e-4576-46af-a852-72f907cedd5e",
      "name": "Fetch Existing Lead IDs",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        576,
        1328
      ],
      "parameters": {
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "YOUR_GOOGLE_SHEET_URL_HERE"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "5651f559-a244-4a6a-83e4-305433b76e50",
      "name": "Merge for Dedup Check",
      "type": "n8n-nodes-base.merge",
      "position": [
        784,
        1248
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "1adc479f-f521-446f-ada1-68152b222c7f",
      "name": "Deduplicate Leads",
      "type": "n8n-nodes-base.code",
      "position": [
        1040,
        1280
      ],
      "parameters": {
        "jsCode": "const allItems = $input.all();\n\nconst newId = allItems[0].json.id;\nconst person = allItems[0].json.person;\nconst name = person.name || `${person.first_name || ''} ${person.last_name || ''}`.trim();\nconst designation = allItems[0].json.designation || '';\n\nconst sheetRows = allItems.slice(1);\nconst existingIds = sheetRows.map(i => i.json['Apollo ID']).filter(Boolean);\n\nconst isDuplicate = existingIds.includes(newId);\n\nreturn [{ json: { \n  id: newId,\n  name: name,\n  designation: designation,\n  isDuplicate: isDuplicate \n} }];\n\n{{ $('Deduplicate Leads').first().json.designation }}"
      },
      "typeVersion": 2
    },
    {
      "id": "868b04b4-f9b4-47c4-86fa-58f0cef5f4ef",
      "name": "Process Each Lead",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        128,
        1328
      ],
      "parameters": {
        "options": {
          "reset": "={{ $json.person }}"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "a4e420a7-09c6-4871-9e69-302870757580",
      "name": "Lead Generation Form",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -512,
        1328
      ],
      "parameters": {
        "options": {},
        "formTitle": "Lead Generation Form",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Job Title",
              "requiredField": true
            },
            {
              "fieldLabel": "Location",
              "requiredField": true
            },
            {
              "fieldType": "number",
              "fieldLabel": "Number of Leads",
              "requiredField": true
            }
          ]
        },
        "formDescription": "Enter details to search and generate leads automatically"
      },
      "typeVersion": 2.3
    },
    {
      "id": "3371908a-881a-446b-b9a7-bbaf4cd0e771",
      "name": "Email Generation Loop",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1776,
        704
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "90fd6eba-0057-4adf-a278-393bb3c71a06",
      "name": "Wait \u2014 Email Cooldown (4s)",
      "type": "n8n-nodes-base.wait",
      "position": [
        2576,
        768
      ],
      "parameters": {
        "amount": 4
      },
      "typeVersion": 1.1
    },
    {
      "id": "225282e1-c035-484c-9271-1db9197a0296",
      "name": "Wait \u2014 Apollo Cooldown (2s)",
      "type": "n8n-nodes-base.wait",
      "position": [
        1584,
        1280
      ],
      "parameters": {
        "amount": 2
      },
      "typeVersion": 1.1
    },
    {
      "id": "7e350226-331c-4fd4-8ea6-eac956f6f33a",
      "name": "Send Cold Email via Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2992,
        160
      ],
      "parameters": {
        "sendTo": "={{ $('Fetch Leads from Sheet').item.json['Email Address '] }}",
        "message": "={{ $json['Email Body'] }}",
        "options": {
          "bccList": "",
          "senderName": "Your Name",
          "appendAttribution": false
        },
        "subject": "={{ $json['Email Subject '] }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f2c7e6f6-8ec7-4781-9099-91acb782e1df",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        2768,
        176
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "6dfab97b-dd54-4e5a-a80f-ce3ce9797e54",
      "name": "Update the Outreach Status",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3216,
        160
      ],
      "parameters": {
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "YOUR_GOOGLE_SHEET_URL_HERE"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.2
    },
    {
      "id": "52bbc219-6de7-4617-bdc9-48c932e28f0f",
      "name": "Filter1",
      "type": "n8n-nodes-base.filter",
      "position": [
        2544,
        176
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "03125e1a-f904-4c79-bec6-aee701c26d95",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json['Outreach Status '] }}",
              "rightValue": "Mail Generated"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "2f2d4586-d06f-4b6a-9ddc-bba53e74d351",
      "name": "Wait \u2014 Email Cooldown (60s)",
      "type": "n8n-nodes-base.wait",
      "position": [
        3440,
        176
      ],
      "parameters": {
        "amount": 60
      },
      "typeVersion": 1.1
    },
    {
      "id": "c896a808-c8d3-4277-9abc-f40c2624c4aa",
      "name": "Fetch Leads for Mail",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2128,
        176
      ],
      "parameters": {
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "YOUR_GOOGLE_SHEET_URL_HERE"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "05e90a43-fc5f-4db2-a2e7-54c9501c7c4f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        640
      ],
      "parameters": {
        "width": 1104,
        "height": 576,
        "content": "## Scrape leads from Apollo and send AI-powered cold emails \u2014 Full B2B Outreach Automation\n\nOVERVIEW\nTwo triggers for complete control over your outreach pipeline.\n\nTRIGGER 1 \u2014 LEAD SCRAPER (Form Trigger)\nFill the form with Job Title, Location and Number of Leads.\nApollo finds, enriches and saves leads to Google Sheet automatically.\n\nTRIGGER 2 \u2014 EMAIL GENERATOR AND SENDER (Manual Trigger)\nRun manually when ready.\nGenerates AI cold emails for all Pending leads, then\nsends emails to all Mail Generated leads via Gmail.\n\nCREDENTIALS REQUIRED\n- Apollo API Key (Header Auth)\n- Google Sheets OAuth2\n- Groq API Key (At console.groq.com)\n- Gmail OAuth2\n\nSETUP INSTRUCTIONS\n- Replace YOUR_GOOGLE_SHEET_URL with your Google Sheet URL\n- Add Apollo API Key in Header Auth credential\n- Add Groq API Key in Groq credential\n- Connect your Gmail account\n- Update the email prompt with your company details"
      },
      "typeVersion": 1
    },
    {
      "id": "8b9c804a-e440-4b75-a37b-4cc165c05819",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        1488
      ],
      "parameters": {
        "color": 7,
        "width": 368,
        "height": 144,
        "content": "## Trigger 1 \u2014Lead Input Form\n\nUser submits job title, location and \nnumber of leads required. This triggers \nthe workflow automatically."
      },
      "typeVersion": 1
    },
    {
      "id": "74c038b1-a187-41a4-afd5-e1f0e14ca8de",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        1616
      ],
      "parameters": {
        "color": 7,
        "width": 528,
        "height": 192,
        "content": "## Lead Discovery and Enrichment\n\nApollo searches for matching leads based \non form input. Each lead is enriched with \nemail, phone number, LinkedIn URL and \ncompany information."
      },
      "typeVersion": 1
    },
    {
      "id": "5c7a3393-bbe4-40b1-b0c8-3d6cd6f38ff3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        1008
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 176,
        "content": "## Duplicate Prevention\n\nEach lead is checked against existing \nrecords in the Google Sheet. Duplicate \nleads are automatically skipped to avoid \nredundant outreach."
      },
      "typeVersion": 1
    },
    {
      "id": "5db27cae-6198-43fd-8d0a-4d7cf7bb63aa",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1936,
        1072
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 144,
        "content": "## Save Leads\n\nAll enriched and verified leads are saved \nto the Google Sheet with outreach status \nset to Pending."
      },
      "typeVersion": 1
    },
    {
      "id": "b333df1a-6671-47bd-b881-0439016119e8",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2144,
        384
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 176,
        "content": "## AI Email Generation\n\nGroq LLM generates a personalized cold \nemail for each lead based on their job \ntitle, company and industry. Subject and \nbody are saved back to the sheet."
      },
      "typeVersion": 1
    },
    {
      "id": "62b69105-1e1f-4ddf-90b0-ef1119f2b11d",
      "name": "Remove Duplicates",
      "type": "n8n-nodes-base.removeDuplicates",
      "position": [
        2336,
        176
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "f8dcde96-44f3-4799-9a08-8a52d0fc7efd",
      "name": "When clicking Execute Workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        1104,
        704
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "d113f0b6-cb1c-4390-a045-7717f4c0e001",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1104,
        448
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 192,
        "content": "## Trigger 2 \u2014 Email Generator and Sender\n\nRun manually when ready to generate and \nsend emails. Generates AI cold emails for \nall Pending leads then sends to all Mail \nGenerated leads via Gmail."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5ab4ffc4-8800-4292-a639-0599c43be7b2",
  "connections": {
    "Filter1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Send Cold Email via Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip Duplicates": {
      "main": [
        [
          {
            "node": "Wait \u2014 Apollo Cooldown (2s)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Process Each Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Email JSON": {
      "ai_outputParser": [
        [
          {
            "node": "AI Cold Email Writer",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Deduplicate Leads": {
      "main": [
        [
          {
            "node": "Skip Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Each Lead": {
      "main": [
        [],
        [
          {
            "node": "Merge for Dedup Check",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Existing Lead IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates": {
      "main": [
        [
          {
            "node": "Filter1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq LLM (Fast AI)": {
      "ai_languageModel": [
        [
          {
            "node": "AI Cold Email Writer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Extract People Data": {
      "main": [
        [
          {
            "node": "Process Each Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Email to Sheet": {
      "main": [
        [
          {
            "node": "Wait \u2014 Email Cooldown (4s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Leads to Sheet": {
      "main": [
        [
          {
            "node": "Process Each Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Cold Email Writer": {
      "main": [
        [
          {
            "node": "Save Email to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Leads for Mail": {
      "main": [
        [
          {
            "node": "Remove Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Pending Leads": {
      "main": [
        [
          {
            "node": "Email Generation Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Generation Form": {
      "main": [
        [
          {
            "node": "Apollo \u2014 Search Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Generation Loop": {
      "main": [
        [
          {
            "node": "Fetch Leads for Mail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Cold Email Writer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge for Dedup Check": {
      "main": [
        [
          {
            "node": "Deduplicate Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Leads from Sheet": {
      "main": [
        [
          {
            "node": "Filter Pending Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apollo \u2014 Search Leads": {
      "main": [
        [
          {
            "node": "Extract People Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Existing Lead IDs": {
      "main": [
        [
          {
            "node": "Merge for Dedup Check",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Format & Clean Lead Data": {
      "main": [
        [
          {
            "node": "Save Leads to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Cold Email via Gmail": {
      "main": [
        [
          {
            "node": "Update the Outreach Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update the Outreach Status": {
      "main": [
        [
          {
            "node": "Wait \u2014 Email Cooldown (60s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apollo \u2014 Enrich Lead Data": {
      "main": [
        [
          {
            "node": "Format & Clean Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait \u2014 Email Cooldown (4s)": {
      "main": [
        [
          {
            "node": "Email Generation Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait \u2014 Apollo Cooldown (2s)": {
      "main": [
        [
          {
            "node": "Apollo \u2014 Enrich Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait \u2014 Email Cooldown (60s)": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking Execute Workflow": {
      "main": [
        [
          {
            "node": "Fetch Leads from Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}