{
  "name": "Puzzle me this #51 — Automated Lead Research & Outreach Pipeline (NeverBounce + Perplexity + OpenAI + Instantly)",
  "nodes": [
    {
      "parameters": {},
      "id": "e5100000-0000-4000-8000-000000000001",
      "name": "When clicking 'Test workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -680,
        240
      ],
      "notes": "Manual trigger for testing pipeline executions or single lead runs."
    },
    {
      "parameters": {
        "operation": "read",
        "sheetId": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
        "range": "Leads!A2:H100",
        "options": {
          "valueRenderOption": "FORMATTED_VALUE"
        }
      },
      "id": "e5100000-0000-4000-8000-000000000002",
      "name": "Get Leads",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        -460,
        240
      ],
      "notes": "Fetches raw prospect rows with Name, Company, Email, Website, and LinkedIn."
    },
    {
      "parameters": {
        "url": "https://api.neverbounce.com/v4/single/check",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "REPLACE_WITH_NEVERBOUNCE_API_KEY"
            },
            {
              "name": "email",
              "value": "={{ $json.Email || $json.email }}"
            },
            {
              "name": "address_info",
              "value": "1"
            }
          ]
        },
        "options": {}
      },
      "id": "e5100000-0000-4000-8000-000000000003",
      "name": "Never Bounce",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -240,
        240
      ],
      "notes": "Verifies email deliverability, MX records, syntax, and disposable status via NeverBounce."
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.result }}",
              "rightValue": "valid",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "e5100000-0000-4000-8000-000000000004",
      "name": "If5",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -20,
        240
      ],
      "notes": "Evaluates email verification result: Branch True for valid emails; Branch False for invalid/risky."
    },
    {
      "parameters": {
        "operation": "update",
        "sheetId": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
        "range": "=Leads!G{{ $node['Get Leads'].json.row_number || 2 }}",
        "options": {},
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "Status",
              "fieldValue": "=Invalid Email ({{ $json.result || 'bad_syntax' }})"
            },
            {
              "fieldId": "Updated_At",
              "fieldValue": "={{ $now.toISO() }}"
            }
          ]
        }
      },
      "id": "e5100000-0000-4000-8000-000000000005",
      "name": "Google Sheets18",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        200,
        420
      ],
      "notes": "Updates spreadsheet to mark the lead as invalid and log the bounce reason."
    },
    {
      "parameters": {
        "amount": 3,
        "unit": "seconds"
      },
      "id": "e5100000-0000-4000-8000-000000000006",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        420,
        420
      ],
      "notes": "Rate-limit backoff buffer before checking the next lead in the batch."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.perplexity.ai/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer REPLACE_WITH_PERPLEXITY_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"sonar-medium-online\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are an elite B2B sales intelligence researcher. Provide 3 factual, recent, verified business highlights about this company or lead: 1) Recent product launch, funding, or press within the last 6 months. 2) Key technology stack or strategic focus. 3) Specific business pain point or growth milestone. Output concise bullet points with verified citations.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Research company: {{ $('Get Leads').item.json.Company }}. Website: {{ $('Get Leads').item.json.Website }}. Prospect: {{ $('Get Leads').item.json.FirstName }} {{ $('Get Leads').item.json.LastName }}, Title: {{ $('Get Leads').item.json.Title }}\"\n    }\n  ],\n  \"temperature\": 0.2\n}",
        "options": {}
      },
      "id": "e5100000-0000-4000-8000-000000000007",
      "name": "Research",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        200,
        140
      ],
      "notes": "Performs real-time web research via Perplexity Sonar search engine."
    },
    {
      "parameters": {
        "jsCode": "// Extract Perplexity response content, citations, and merge with lead info\nconst lead = $('Get Leads').item.json;\nconst perplexity = $json;\n\nconst content = perplexity.choices?.[0]?.message?.content || 'No recent news found.';\nconst citations = perplexity.citations || [];\n\nreturn [{\n  json: {\n    lead: lead,\n    researchSummary: content,\n    citations: citations,\n    researchTimestamp: new Date().toISOString()\n  }\n}];"
      },
      "id": "e5100000-0000-4000-8000-000000000008",
      "name": "Code2",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        420,
        140
      ],
      "notes": "Structures Perplexity findings into normalized research payload."
    },
    {
      "parameters": {
        "agent": "toolsAgent",
        "promptType": "define",
        "text": "=Generate a 1-2 sentence personalized cold outreach icebreaker for {{ $json.lead.FirstName }} at {{ $json.lead.Company }}.\n\nContext & Research Data:\n{{ $json.researchSummary }}\n\nRules:\n1. Hook directly into their specific recent accomplishment or milestone.\n2. Do NOT use fake praise like \"Congrats on your amazing role!\". Be specific and professional.\n3. Keep it under 35 words. Write in natural conversational tone.",
        "options": {
          "systemMessage": "=You are an expert outbound copywriter crafting high-converting cold email openings. Your goal is to establish instant credibility by demonstrating genuine, factual awareness of the prospect's recent business activity."
        }
      },
      "id": "e5100000-0000-4000-8000-000000000009",
      "name": "AI Agent4",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        680,
        140
      ],
      "notes": "LangChain Agent synthesizing research into tailored 1-2 sentence icebreaker hook."
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "options": {
          "temperature": 0.3
        }
      },
      "id": "e5100000-0000-4000-8000-000000000010",
      "name": "OpenAI Chat Model4",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        680,
        340
      ],
      "notes": "OpenAI GPT-4o language model powering the icebreaker agent."
    },
    {
      "parameters": {
        "jsCode": "// Prepare Instantly.ai Add Lead API payload\nconst lead = $('Code2').item.json.lead;\nconst icebreaker = $json.output || $json.text || '';\nconst research = $('Code2').item.json.researchSummary;\n\nreturn [{\n  json: {\n    campaign_id: 'CAMP_B2B_OUTREACH_2026',\n    skip_if_in_workspace: true,\n    leads: [\n      {\n        email: lead.Email || lead.email,\n        first_name: lead.FirstName || lead.first_name,\n        last_name: lead.LastName || lead.last_name,\n        company_name: lead.Company || lead.company,\n        website: lead.Website || lead.website || '',\n        custom_variables: {\n          icebreaker: icebreaker.trim(),\n          research_intel: research.substring(0, 300),\n          source: 'n8n_automated_pipeline_v51'\n        }\n      }\n    ]\n  }\n}];"
      },
      "id": "e5100000-0000-4000-8000-000000000011",
      "name": "Code1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        940,
        140
      ],
      "notes": "Formats lead and generated icebreaker for the Instantly.ai API."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.instantly.ai/api/v2/campaigns/CAMP_B2B_OUTREACH_2026/leads",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer REPLACE_WITH_INSTANTLY_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}",
        "options": {}
      },
      "id": "e5100000-0000-4000-8000-000000000012",
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1160,
        140
      ],
      "notes": "Pushes enriched lead directly into Instantly cold outreach campaign."
    },
    {
      "parameters": {
        "operation": "update",
        "sheetId": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
        "range": "=Leads!G{{ $('Get Leads').item.json.row_number || 2 }}",
        "options": {},
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "Status",
              "fieldValue": "Enriched & Added to Instantly"
            },
            {
              "fieldId": "Icebreaker",
              "fieldValue": "={{ $('Code1').item.json.leads[0].custom_variables.icebreaker }}"
            },
            {
              "fieldId": "Verified_Deliverability",
              "fieldValue": "100% Valid"
            },
            {
              "fieldId": "Processed_At",
              "fieldValue": "={{ $now.toISO() }}"
            }
          ]
        }
      },
      "id": "e5100000-0000-4000-8000-000000000013",
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1380,
        140
      ],
      "notes": "Confirms pipeline completion in Google Sheets with generated icebreaker and status."
    }
  ],
  "connections": {
    "When clicking 'Test workflow'": {
      "main": [
        [
          {
            "node": "Get Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Leads": {
      "main": [
        [
          {
            "node": "Never Bounce",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Never Bounce": {
      "main": [
        [
          {
            "node": "If5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If5": {
      "main": [
        [
          {
            "node": "Research",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Google Sheets18",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets18": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Get Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Research": {
      "main": [
        [
          {
            "node": "Code2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code2": {
      "main": [
        [
          {
            "node": "AI Agent4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model4": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent4",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent4": {
      "main": [
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code1": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
