{
  "name": "Lead Generation Tool in n8n: Apify, AI and Gmail (free JSON)",
  "nodes": [
    {
      "id": "e106ff39-a4ce-4859-9b4b-a1b6e4640bcf",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        -240,
        576
      ],
      "parameters": {
        "unit": "minutes",
        "amount": "={{ $json.delayMinutes }}\n"
      },
      "typeVersion": 1.1
    },
    {
      "id": "0ce9db68-c58b-4b09-8e85-fc7a49ea6307",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -16,
        576
      ],
      "parameters": {
        "options": {
          "returnFirstMatch": true
        },
        "filtersUI": {
          "values": [
            {
              "lookupValue": "not sent",
              "lookupColumn": "Status"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "2cfca14f-0c63-49f6-b4c1-597a15ba1fc2",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        208,
        576
      ],
      "parameters": {
        "text": "=Don't change the structure of the email below:\n\n\n\nHi {{ $json['Full Name'] }},\n\nPASTE YOUR FIRST EMAIL HERE.\n\nBest,\nYOUR_NAME",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "4645e708-502a-4593-855a-03813497815e",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        176,
        816
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "196fe8a2-9759-4ffc-a2e8-2b2ffc733ebf",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        560,
        576
      ],
      "parameters": {
        "sendTo": "={{ $('Get row(s) in sheet').item.json.Email }}",
        "message": "={{ $json.output }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "YOUR_SUBJECT_LINE",
        "emailType": "text"
      },
      "typeVersion": 2.1
    },
    {
      "id": "5e7a9e77-3743-4d98-ba28-a11761c0a329",
      "name": "Update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        784,
        576
      ],
      "parameters": {
        "columns": {
          "value": {
            "Email": "={{ $('Get row(s) in sheet').item.json.Email }}",
            "Status": "sent",
            "Date sent": "={{ new Date().toLocaleString() }}\n\n\n\n"
          },
          "schema": [
            {
              "id": "Full Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Full Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Title",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Personal LinkedIn",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Personal LinkedIn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Company Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Website",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Company Website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Followed up",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Followed up",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date sent",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date sent",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "44668354-7b56-4ebd-b2f9-63c50c8527cd",
      "name": "Add to Google Sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        960,
        144
      ],
      "parameters": {
        "columns": {
          "value": {
            "Email": "={{ $('If').item.json.output.email }}",
            "Title": "={{ $('If').item.json.output.title }}",
            "Status": "not sent",
            "Full Name": "={{ $('If').item.json.output.fullName }}",
            "Followed up": "not sent",
            "Company Name": "={{ $('If').item.json.output.companyName }}",
            "Company Website": "={{ $('If').item.json.output.companyWebsite }}",
            "Personal LinkedIn": "={{ $('If').item.json.output.LinkedIn }}"
          },
          "schema": [
            {
              "id": "Full Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Full Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Personal LinkedIn",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Personal LinkedIn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Website",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company Website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Followed up",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Followed up",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date sent",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Date sent",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "0b11e707-4df3-4d55-acf9-f1dd40be47b0",
      "name": "Parse Lead Data1",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "onError": "continueErrorOutput",
      "position": [
        -176,
        96
      ],
      "parameters": {
        "text": "=Name: {{ $json.name }}\n\nTitle: {{ $json.title }}\n\nEmail: {{ $json.email }}\n\nLinkedIn: {{ $json.linkedin_url }}\n\nOrg Name: {{ $json.organization_name }}\n\nOrg Website: {{ $json.organization_website_url }}\n\n\n\n\n\n",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "=You are a sophisticated AI data-processing engine. Your task is to receive a raw JSON object for a single business prospect, perform two critical actions, and then provide your response in a specific JSON format.\n\n**Your Instructions:**\n\n1.  **EXTRACT KEY DATA:** You must parse the raw JSON input to find and extract the following specific data points. If a field is not present, use a value of `null`.\n    * **Full Name:** Look for `first_name` and `last_name`.\n    * **Email:** Find the first available email address. Look in fields like `emails` or `personal_emails`.\n    * **LinkedIn** Look for the 'linkedin_url'\n    * **Title:** Look for the `title` field.\n    * **Company Name:** Look for the `organization_name` field.\n    * **Company Website:** Look for the `organization_website` field.\n  \n\n2.  **FORMAT THE OUTPUT:** You MUST structure your entire response as a single, clean JSON object. The object should contain exactly the keys listed below. Do not include any other text, explanations, or greetings in your response—ONLY the final JSON object.\n\n**Required Output Format:**\n{\n  \"fullName\": \"...\",\n  \"email\": \"...\",\n  \"title\": \"...\",\n  \"LinkedIn\": \"...\",\n  \"companyName\": \"...\",\n  \"companyWebsite\": \"...\"\n}"
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "c6bd294f-d484-4385-9a6f-6d8982e836e2",
      "name": "OpenAI Chat Model3",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -224,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "f3bc251a-22ce-4127-8aef-42ba62583d55",
      "name": "Structured Output Parser1",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        0,
        320
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"fullName\": \"Maya Reed\",\n  \"email\": \"maya@example.com\",\n  \"title\": \"Founder\",\n  \"LinkedIn\": \"https://www.linkedin.com/in/example-maya-reed\",\n  \"companyName\": \"Lantern Studio\",\n  \"companyWebsite\": \"https://www.example.com\"\n}\n"
      },
      "typeVersion": 1.3
    },
    {
      "id": "3f30569c-5d9c-4dd7-84d2-972b6bc8ee4c",
      "name": "When clicking ‘Execute workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -768,
        96
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "44589449-d7bd-4d54-9754-916040cd5257",
      "name": "Add to Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2848,
        208
      ],
      "parameters": {
        "columns": {
          "value": {
            "Email": "={{ $json.output.email }}",
            "Title": "={{ $json.output.title }}",
            "Full Name": "={{ $json.output.fullName }}",
            "Company Name": "={{ $json.output.companyName }}",
            "Company Website": "={{ $json.output.companyWebsite }}",
            "Personal LinkedIn": "={{ $json.output.LinkedIn }}",
            "Status": "not sent",
            "Followed up": "not sent"
          },
          "schema": [
            {
              "id": "Full Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Full Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Personal LinkedIn",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Personal LinkedIn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Website",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company Website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Followed up",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Followed up",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "d3a1e7c2-a664-42b7-8e10-349b69f58fb8",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "disabled": true,
      "position": [
        1696,
        208
      ],
      "parameters": {
        "options": {},
        "formTitle": "Apollo + Apify Lead Generation",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Job Title",
              "placeholder": "Founder, Engineer, Owner"
            },
            {
              "fieldType": "dropdown",
              "fieldLabel": "Company Size",
              "fieldOptions": {
                "values": [
                  {
                    "option": "1-10"
                  },
                  {
                    "option": "11-50"
                  },
                  {
                    "option": "51-200"
                  },
                  {
                    "option": "201-1000"
                  },
                  {
                    "option": "10001-5000"
                  },
                  {
                    "option": "5001-10000"
                  },
                  {
                    "option": "10001-100000"
                  }
                ]
              }
            },
            {
              "fieldLabel": "Keywords",
              "placeholder": "Keywords relevant to the contact or company"
            },
            {
              "fieldLabel": "Location",
              "placeholder": "United States, California, London"
            }
          ]
        },
        "formDescription": "Describe the types of leads you are trying to find."
      },
      "typeVersion": 2.2
    },
    {
      "id": "873f3e58-b968-4184-9e1a-d9a7f576e895",
      "name": "Apollo URL Generator",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1920,
        208
      ],
      "parameters": {
        "text": "=Job Title: {{ $json['Job Title'] }}\n\nCompany Size: {{ $json['Company Size'] }}\n\nKeywords: {{ $json.Keywords }}\n\nLocation: {{ $json.Location }}\n\n\n",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "=You are an expert Apollo search URL generator.\n\nYour task is to take key-value data from a form submission and turn it into a precise Apollo Search URL. You will only receive input for the fields listed below.\n\nSupported Search Fields\nYou only support the following four fields from the form input:\n\npersonLocation: The location of the person. Maps to the personLocations[] parameter.\njobTitle: The person's job title. Maps to the personTitles[] parameter.\ncompanySize: The employee range of the company. Maps to the organizationNumEmployeesRanges[] parameter.\nkeywords: Specific keyword tags for the organization. Maps to the qOrganizationKeywordTags[] parameter.\nDo not add or infer any other fields or parameters.\n\nURL Template\nUse the following URL template:\n\n\nhttps://app.apollo.io/#/people?{field1}={value1}&{field2}={value2}&...\n\n\n\n\nExample:\n\nInput\npersonLocation: New York\njobTitle: VP of Engineering\ncompanySize: 51-200\nkeywords: Healthcare AI\n\n\nOutput\n\nhttps://app.apollo.io/#/people?personLocations[]=New%20York&personTitles[]=VP%20of%20Engineering&organizationNumEmployeesRanges[]=51%2C200&qOrganizationKeywordTags[]=Healthcare%20AI"
            }
          ]
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "c589a388-9e33-462f-b25a-4f8d578ff8ff",
      "name": "Run Apify",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2272,
        208
      ],
      "parameters": {
        "url": "https://api.apify.com/v2/acts/YOUR_APIFY_ACTOR_ID/run-sync-get-dataset-items",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"getPersonalEmails\": true,\n    \"getWorkEmails\": true,\n    \"totalRecords\": 5,\n    \"url\": \"{{ $json.text }}\"\n}",
        "sendBody": true,
        "sendHeaders": false,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "dfd4c6c1-5339-4f0d-88e5-dfacdea6eac0",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2512,
        432
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "46ff8717-17b6-4a20-aa7d-27b141b4616f",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        2640,
        432
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"fullName\": \"Maya Reed\",\n  \"email\": \"maya@example.com\",\n  \"title\": \"Founder\",\n  \"LinkedIn\": \"https://www.linkedin.com/in/example-maya-reed\",\n  \"companyName\": \"Lantern Studio\",\n  \"companyWebsite\": \"https://www.example.com\"\n}\n"
      },
      "typeVersion": 1.2
    },
    {
      "id": "f2dc9fcb-e732-40d9-a8c2-f7aae1a4420e",
      "name": "Parse Lead Data",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        2496,
        208
      ],
      "parameters": {
        "text": "=Name: {{ $json.name }}\n\nTitle: {{ $json.title }}\n\nEmail: {{ $json.email }}\n\nLinkedIn: {{ $json.linkedin_url }}\n\nOrg Name: {{ $json.organization_name }}\n\nOrg Website: {{ $json.organization_website_url }}\n\n\n\n\n\n",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "=You are a sophisticated AI data-processing engine. Your task is to receive a raw JSON object for a single business prospect, perform two critical actions, and then provide your response in a specific JSON format.\n\n**Your Instructions:**\n\n1.  **EXTRACT KEY DATA:** You must parse the raw JSON input to find and extract the following specific data points. If a field is not present, use a value of `null`.\n    * **Full Name:** Look for `first_name` and `last_name`.\n    * **Email:** Find the first available email address. Look in fields like `emails` or `personal_emails`.\n    * **LinkedIn** Look for the 'linkedin_url'\n    * **Title:** Look for the `title` field.\n    * **Company Name:** Look for the `organization_name` field.\n    * **Company Website:** Look for the `organization_website` field.\n  \n\n2.  **FORMAT THE OUTPUT:** You MUST structure your entire response as a single, clean JSON object. The object should contain exactly the keys listed below. Do not include any other text, explanations, or greetings in your response—ONLY the final JSON object.\n\n**Required Output Format:**\n{\n  \"fullName\": \"...\",\n  \"email\": \"...\",\n  \"title\": \"...\",\n  \"LinkedIn\": \"...\",\n  \"companyName\": \"...\",\n  \"companyWebsite\": \"...\"\n}"
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "c2aaeb6d-a672-4b5a-9c26-9ec9fe676d2d",
      "name": "OpenAI Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2000,
        432
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "gpt-4.1"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "bffff111-b13c-46e3-9dc5-0308a9deecee",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -672,
        576
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 100
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "252bde84-f9c3-42bd-ac90-1671d3b63651",
      "name": "Wait1",
      "type": "n8n-nodes-base.wait",
      "position": [
        -256,
        1072
      ],
      "parameters": {
        "amount": "={{ $json.delayMinutes }}\n"
      },
      "typeVersion": 1.1
    },
    {
      "id": "ed24a32a-e6fc-44d3-95b0-7b8a81ce0c59",
      "name": "Get row(s) in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -32,
        1072
      ],
      "parameters": {
        "options": {
          "returnFirstMatch": true
        },
        "filtersUI": {
          "values": [
            {
              "lookupValue": "not sent",
              "lookupColumn": "Followed up"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "d4f06004-f3ab-4a1f-be45-673b4e02d18e",
      "name": "AI Agent1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        704,
        1072
      ],
      "parameters": {
        "text": "=Don't change the structure of the email below:\n\n\n\n\nHi {{ $json['Full Name'] }},\n\nI wasn’t sure if you had a chance to see my last note.\n\nPASTE THE REST OF YOUR FOLLOW-UP HERE.\n\nBest,\nYOUR_NAME",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "a529d18d-1166-4d68-a36c-9af6173d50c6",
      "name": "Send a message1",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1088,
        1072
      ],
      "parameters": {
        "sendTo": "={{ $('Get row(s) in sheet1').item.json.Email }}",
        "message": "={{ $json.output }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "=Hey {{ $('Get row(s) in sheet1').item.json['Full Name'] }}, I wanted to bump this up in case you missed it",
        "emailType": "text"
      },
      "typeVersion": 2.1
    },
    {
      "id": "c131a939-28ee-424c-bf9f-7c31a94e007b",
      "name": "Update row in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1344,
        1072
      ],
      "parameters": {
        "columns": {
          "value": {
            "Email": "={{ $('Get row(s) in sheet1').item.json.Email }}",
            "Followed up": "sent"
          },
          "schema": [
            {
              "id": "Full Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Full Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Title",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Personal LinkedIn",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Personal LinkedIn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Company Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company Website",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Company Website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Followed up",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Followed up",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "c8f62500-05a7-446d-9b5e-5d377732cd8e",
      "name": "Schedule Trigger1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -688,
        1072
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 100
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "72f5255a-1770-42a9-95cd-da78cf724320",
      "name": "OpenAI Chat Model4",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        768,
        1392
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "37ed477a-4c47-4763-b81a-3811c205bfe7",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "position": [
        448,
        1072
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7819ddc2-23f4-4456-8870-9a056af394c7",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.canSendFollowUp }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "06e93388-90b4-4fc9-81be-c2acc070f759",
      "name": "Get row(s) in sheet2",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -592,
        96
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Leads"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.7,
      "alwaysOutputData": false
    },
    {
      "id": "8f973349-bc9a-4969-b522-36b2a6342e04",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        288,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d094f9ec-b150-4b72-9793-8113829b8bed",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.output.email }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "55a98bc4-4bb5-48ce-b7b8-9d56d7e0241d",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        896,
        -32
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "1d3a7c2a-a4a5-4973-bed3-f23e7951e1de",
      "name": "If2",
      "type": "n8n-nodes-base.if",
      "position": [
        624,
        -48
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "07b00e22-98e5-44b6-bc2b-5f7a9e45206f",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "=",
              "rightValue": "={{ $('Parse Lead Data1').item.json.output.email }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6a36210f-0618-4ff7-b49a-93d45032864f",
      "name": "Delay generator",
      "type": "n8n-nodes-base.code",
      "position": [
        -480,
        1072
      ],
      "parameters": {
        "jsCode": "// Random delay between 5 and 20 minutes\nconst minMinutes = 5;\nconst maxMinutes = 20;\nconst delayMinutes = Math.floor(Math.random() * (maxMinutes - minMinutes + 1)) + minMinutes;\n\nreturn [\n  {\n    json: {\n      delayMinutes: delayMinutes,\n      delayMilliseconds: delayMinutes * 60 * 1000\n    }\n  }\n];\n\n"
      },
      "typeVersion": 2
    },
    {
      "id": "0cb8f2a6-70cd-43e0-a824-c784baaa226d",
      "name": "Time checker",
      "type": "n8n-nodes-base.code",
      "position": [
        240,
        1072
      ],
      "parameters": {
        "jsCode": "const dateString = $input.item.json[\"Date sent\"];\nconst [datePart, timePart] = dateString.split(', ');\nconst [month, day, year] = datePart.split('/');\nconst dateSent = new Date(year, month - 1, day);\nconst currentDate = new Date();\nconst today = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());\nconst timeDifference = today.getTime() - dateSent.getTime();\nconst daysDifference = timeDifference / (1000 * 60 * 60 * 24);\n\nreturn {\n  ...$input.item.json,  // Keep all original data\n  canSendFollowUp: daysDifference >= 2,\n  daysPassed: daysDifference\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "8a19f9cc-d672-4331-a505-7c66011b7b0f",
      "name": "Delay generator1",
      "type": "n8n-nodes-base.code",
      "position": [
        -464,
        576
      ],
      "parameters": {
        "jsCode": "// Random delay between 5 and 20 minutes\nconst minMinutes = 5;\nconst maxMinutes = 20;\nconst delayMinutes = Math.floor(Math.random() * (maxMinutes - minMinutes + 1)) + minMinutes;\n\nreturn [\n  {\n    json: {\n      delayMinutes: delayMinutes,\n      delayMilliseconds: delayMinutes * 60 * 1000\n    }\n  }\n];\n\n"
      },
      "typeVersion": 2
    },
    {
      "id": "f6791d1e-8d8a-41d6-bd59-8c4773367625",
      "name": "proper json",
      "type": "n8n-nodes-base.code",
      "position": [
        -416,
        96
      ],
      "parameters": {
        "jsCode": "// Paste the data returned by your Apify run here, replacing the example record below.\n// Keep the square brackets. Each record is one lead.\n// The record below is invented. Delete it before you use your own data.\nconst rawData = [\n  {\n    \"first_name\": \"Maya\",\n    \"last_name\": \"Reed\",\n    \"name\": \"Maya Reed\",\n    \"email\": \"maya@example.com\",\n    \"title\": \"Founder\",\n    \"linkedin_url\": \"https://www.linkedin.com/in/example-maya-reed\",\n    \"organization_name\": \"Lantern Studio\",\n    \"organization_website_url\": \"https://www.example.com\"\n  }\n];\n\nreturn rawData.map(item => ({ json: item }));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "716182d1-a069-46a4-ae80-d07cfd8f53bd",
      "name": "Before you turn it on",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1400,
        -120
      ],
      "typeVersion": 1,
      "parameters": {
        "color": 4,
        "width": 620,
        "height": 760,
        "content": "## Before you turn it on\n\nThis file holds four flows on one canvas. Replace every placeholder:\n\n- `YOUR_GOOGLE_SHEET_ID`, in every Google Sheets node, and a tab named `Leads`\n- `YOUR_APIFY_ACTOR_ID`, in Run Apify\n- `YOUR_SUBJECT_LINE` and `YOUR_NAME`, and the sample text in the two AI Agent nodes\n\nThen add your own credentials: Google Sheets, OpenAI, Gmail, Apify.\n\nThe sheet needs these columns, spelled exactly: `Full Name`, `Email`, `Title`, `Personal LinkedIn`, `Company Name`, `Company Website`, `Status`, `Followed up`, `Date sent`. Keep at least one row under the headers.\n\nFirst run: use your own email address as the only lead. Switch the two schedules on only after that.\n\nThe file was checked for structure only. It was not run against live accounts."
      }
    },
    {
      "id": "3babe59d-af0a-44bd-99a8-bc7c7f2aab1c",
      "name": "The four flows",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1400,
        700
      ],
      "typeVersion": 1,
      "parameters": {
        "color": 5,
        "width": 620,
        "height": 600,
        "content": "## The four flows\n\n1. Form flow (the form trigger is switched off in the file): form, Apollo search URL, Apify, AI parsing, Google Sheet.\n2. Paste flow, started by hand: reads the sheet, then adds the leads you pasted into the node called proper json.\n3. First email: `Schedule Trigger`, picks one lead with Status `not sent`, writes the email, sends it by Gmail.\n4. Follow-up: `Schedule Trigger1`, picks one lead with Followed up `not sent`, checks the date, sends the follow-up.\n\nThe flows do not feed each other automatically. Apify results do not reach the paste flow by themselves."
      }
    },
    {
      "id": "677c0c89-0ac6-4534-ad54-c3e32cb768a6",
      "name": "What it does not do",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1400,
        1340
      ],
      "typeVersion": 1,
      "parameters": {
        "color": 6,
        "width": 620,
        "height": 600,
        "content": "## What it does not do\n\n- It does not check whether a lead replied before it follows up.\n- It has no unsubscribe link and no bounce handling.\n- The follow-up wait has no unit written in the file. Check it in the Wait1 node.\n- Adding a lead whose email is already in the sheet resets its two status columns to `not sent`.\n- Do not scrape or email people without checking the terms of the services involved and the rules that apply where you and your leads are."
      }
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "If2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If2": {
      "main": [
        [],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait1": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "Send a message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Apify": {
      "main": [
        [
          {
            "node": "Parse Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "proper json": {
      "main": [
        [
          {
            "node": "Parse Lead Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Time checker": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message": {
      "main": [
        [
          {
            "node": "Update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delay generator": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Add to Google Sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Lead Data": {
      "main": [
        [
          {
            "node": "Add to Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message1": {
      "main": [
        [
          {
            "node": "Update row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delay generator1": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Lead Data1": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Delay generator1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "Delay generator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Apollo URL Generator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Parse Lead Data",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Apollo URL Generator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "Parse Lead Data1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model4": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add to Google Sheet1": {
      "main": [
        [
          {
            "node": "If2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apollo URL Generator": {
      "main": [
        [
          {
            "node": "Run Apify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet1": {
      "main": [
        [
          {
            "node": "Time checker",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet2": {
      "main": [
        [
          {
            "node": "proper json",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Parse Lead Data",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser1": {
      "ai_outputParser": [
        [
          {
            "node": "Parse Lead Data1",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}