{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI lead scoring from a form with Apollo, Groq and Gmail",
  "tags": [],
  "nodes": [
    {
      "id": "d33856c0-ae76-494d-aa57-39ffe8de3852",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -540,
        -20
      ],
      "parameters": {
        "options": {},
        "formTitle": "Contact us",
        "formFields": {
          "values": [
            {
              "fieldLabel": "What's your Full Name?",
              "placeholder": "e.g. John Wich",
              "requiredField": true
            },
            {
              "fieldType": "email",
              "fieldLabel": "What is your email address?",
              "placeholder": "e.g. user@example.com",
              "requiredField": true
            },
            {
              "fieldType": "number",
              "fieldLabel": "What's your phone number?",
              "placeholder": "e.g. 1234567890",
              "requiredField": true
            },
            {
              "fieldLabel": "What's your Linkedin Profile URL"
            }
          ]
        },
        "formDescription": "get back to you"
      },
      "typeVersion": 2.2
    },
    {
      "id": "87e4f3a8-8f35-4320-9ddc-218bd8f1ccd0",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -320,
        -20
      ],
      "parameters": {
        "url": "https://api.apollo.io/api/v1/people/match",
        "method": "POST",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $json['What\\'s your Full Name?'] }}"
            },
            {
              "name": "email",
              "value": "={{ $json['What is your email address?'] }}"
            },
            {
              "name": "reveal_phone_number",
              "value": "={{ $json['What\\'s your phone number?'] }}"
            },
            {
              "name": "linkedin_url",
              "value": "={{ $json['What\\'s your Linkedin Profile URL'] }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5aac3e51-fd45-4f7c-99e1-7b81b1a6ea8b",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        520,
        -40
      ],
      "parameters": {
        "text": "=You are a professional B2B sales assistant.\n\nCompose a short, professional, and polite outreach email to schedule a call with the following lead.\n\nTone: concise and respectful. The goal is to open a conversation and set up a meeting.\n\nUse this format:\n---\nSend a message in Gmail:\nTo: {{ $('HTTP Request').item.json.person.email }}\nSubject: YOUR_SUBJECT_LINE\n\nHi {{ $('HTTP Request').item.json.person.name }},\n\nI hope this message finds you well.\n\nI’m reaching out from YOUR_COMPANY_NAME—YOUR_SERVICE_DESCRIPTION. Given your role at {{ $('HTTP Request').item.json.person.employment_history[0].organization_name }}, I’d love to briefly connect and explore potential synergies.\n\nWould you be available for a quick call sometime this week?\n\nBest regards,  \nYOUR_NAME  \nYOUR_COMPANY_NAME\n---\n\nHere is the lead detail:\nName: {{ $('HTTP Request').item.json.person.name }}\nEmail: {{ $('HTTP Request').item.json.person.email }}\nJob Title: {{ $('HTTP Request').item.json.person.title }}\nOrganization: {{ $('HTTP Request').item.json.person.employment_history[0].organization_name }}\n\nInstructions:\nTools - Send a message in Gmail Tools for send mails",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2
    },
    {
      "id": "02cd5fdd-1baa-4a03-8832-af83476eec98",
      "name": "Send a message in Gmail",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        600,
        200
      ],
      "parameters": {
        "sendTo": "={{ $('HTTP Request').item.json.person.email }}",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "options": {},
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', ``, 'string') }}",
        "emailType": "text"
      },
      "typeVersion": 2.1
    },
    {
      "id": "cae69208-18b5-493b-8f14-809e0180a868",
      "name": "Groq Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        480,
        200
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "fac878f8-18eb-482c-a889-5d694549af6c",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        720,
        200
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "da7ad0ef-87ae-4da0-bee0-d464c7e33d3c",
      "name": "Append row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        920,
        -40
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={{ $('On form submission').item.json[\"What's your Full Name?\"] }}",
            "Email": "={{ $('On form submission').item.json[\"What is your email address?\"] }}",
            "Phone": "={{ $('On form submission').item.json[\"What's your phone number?\"] }}",
            "Job Title ": "={{ $('HTTP Request').item.json.person.title }}",
            "Linkedin URL": "={{ $('On form submission').item.json[\"What's your Linkedin Profile URL\"] }}",
            "Organization": "={{ $('HTTP Request').item.json.person.employment_history[0].organization_name }}"
          },
          "schema": [
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Job Title ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Job Title ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Organization",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Organization",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Linkedin URL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Linkedin URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Lead Potential",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Lead Potential",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "b0c08c59-1116-44ed-914f-2e71e43d3208",
      "name": "AI Agent1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -100,
        -20
      ],
      "parameters": {
        "text": "=You are an expert lead qualifier.\n\nScore the lead from 1 to 10 based on these two criteria:\n\n— INDUSTRY MATCH (5 points max) —\n- 5 points: Industry is AI, Artificial Intelligence, Machine Learning, Data Science\n- 3-4 points: Industry is closely related (e.g., analytics, automation, enterprise AI tools)\n- 0-2 points: Unrelated industry\n\n— JOB TITLE MATCH (5 points max) —\n- 5 points: Decision-makers or influencers in AI (e.g., Head of AI, AI Director, CTO, AI Product Manager)\n- 3-4 points: Mid-level AI professionals (e.g., ML Engineer, Data Scientist)\n- 0-2 points: Not related to AI or junior roles\n\nReturn **only a single digit between 1 and 10** — no explanation, no labels, no extra text. and the data type must be a number\n\nLead details:\nName: {{ $json.person.name }}\nJob Title: {{ $json.person.title }}\nOrganization: {{ $json.person.employment_history[0].organization_name }}\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "e4e59a80-4c68-4880-accd-bd3be08cb759",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        260,
        -20
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "eb511082-5f34-4027-993b-a787340fc4ea",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{Number($json.output)}}",
              "rightValue": 6
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "7aeac238-77c1-43ec-a189-2b69e72f745c",
      "name": "Groq Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        -20,
        200
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "fa0db3cb-6bdf-46f4-9135-d2b149ca15a1",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -540,
        180
      ],
      "parameters": {
        "path": "lead-intake",
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "e74c132d-0270-4585-ace8-0651fa4d9617",
      "name": "Google Sheets Trigger",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "position": [
        -560,
        -240
      ],
      "parameters": {
        "event": "rowAdded",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ff9ef01d-7705-42d0-8f65-5e2a2405f882",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -600,
        -480
      ],
      "parameters": {
        "width": 250,
        "height": 170,
        "content": "## 1. Intake\n\nThe form trigger collects name, email, phone and LinkedIn URL. The Webhook and the Google Sheets Trigger also lead to the Apollo step, but only the form's field names match the expressions downstream.",
        "color": 5
      }
    },
    {
      "id": "d13c16ec-2f6e-4cae-a61b-f9ac1bfd50ba",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -330,
        -480
      ],
      "parameters": {
        "width": 250,
        "height": 170,
        "content": "## 2. Enrich\n\nThe HTTP Request node asks Apollo to match the person. Add your Apollo API key through a Header Auth credential, never in the node.",
        "color": 5
      }
    },
    {
      "id": "24a73272-f2bb-4d48-977e-929030081d6d",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -90,
        -480
      ],
      "parameters": {
        "width": 250,
        "height": 170,
        "content": "## 3. Score\n\nThe first AI Agent returns a number from 1 to 10 from job title and organization. The If node lets 6 or more continue. Lower scores stop here and are not logged.",
        "color": 2
      }
    },
    {
      "id": "e0af97fd-6c2b-4758-a1c8-e6d2ce00b2f5",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        190,
        -480
      ],
      "parameters": {
        "width": 250,
        "height": 170,
        "content": "## 4. Write and send\n\nThe second AI Agent writes the email and sends it through the Gmail tool to the email address Apollo returns for the person, which may differ from the one typed in the form. No human approves it first.",
        "color": 3
      }
    },
    {
      "id": "2455ba9e-a94e-4f0a-b7d1-a3a5f86119d2",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        880,
        -480
      ],
      "parameters": {
        "width": 250,
        "height": 170,
        "content": "## 5. Log\n\nAppend row in sheet saves the lead. The sheet needs these headers exactly, including the space after Job Title: Name, Phone, Email, Job Title , Organization, Linkedin URL, Lead Potential. The score is not written to Lead Potential.",
        "color": 6
      }
    },
    {
      "id": "3d6a6249-eb7c-4d5f-bc90-dacf6812cc59",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -600,
        330
      ],
      "parameters": {
        "width": 640,
        "height": 330,
        "content": "## Before you run it\n\nReplace every YOUR_ value (sheet ID, company name, what you offer, your name, subject line). Connect your own Apollo header credential, Groq, Gmail and Google Sheets credentials, and choose a Groq model in both Groq nodes.\n\nThe Google Sheets Trigger has no document selected. Select one or delete the node. If it watches the same sheet that Append row in sheet writes to, every logged lead would start the flow again.\n\nThe workflow is saved inactive. Test with your own email address first, using the form's test URL.",
        "color": 7
      }
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message in Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}