{
  "id": "IADFiILq2xQHLi7X",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "ZOHO CRM - AI-POWERED LEAD QUALIFICATION",
  "tags": [],
  "nodes": [
    {
      "id": "36104a8b-da42-4369-94e8-357509f9f687",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        144,
        128
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c68028a2-8a42-41e8-8c18-d0d08720b6a2",
      "name": "Compute Last Check",
      "type": "n8n-nodes-base.code",
      "position": [
        496,
        224
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const nowUtc = new Date();\nconst tzOffset = nowUtc.getTimezoneOffset(); // in minutes\nconst lookbackMinutes = 10; // same as trigger frequency\nconst lastCheckUtc = new Date(nowUtc.getTime() - lookbackMinutes * 60 * 1000);\n\nfunction formatWithOffset(date) {\n  const pad = (n) => String(n).padStart(2, '0');\n  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}+05:30`;\n}\n\nreturn { json: { lastCheck: formatWithOffset(lastCheckUtc) } };\n"
      },
      "typeVersion": 2
    },
    {
      "id": "d12921bc-1897-463b-ad7d-3ecde29d3d57",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        752,
        112
      ],
      "parameters": {
        "mode": "combine",
        "options": {
          "includeUnpaired": false
        },
        "combinationMode": "mergeByPosition"
      },
      "typeVersion": 2
    },
    {
      "id": "c6954c0b-ce73-46ed-97ba-025d7412680d",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        1360,
        112
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const website = $('Get many leads').item.json.Website || \"\";\n// const domain = email.includes('@') ? email.split('@')[1] : '';\nreturn { json: { ...$json, website } };\n"
      },
      "typeVersion": 2
    },
    {
      "id": "85791fde-2079-4137-8da2-c021eda43e3f",
      "name": "Enrich Lead (PDL)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1568,
        112
      ],
      "parameters": {
        "url": "=https://api.peopledatalabs.com/v5/company/enrich?website={{ $json.website }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": ""
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "fddde836-96f9-42a3-82c3-1c0cf753b724",
      "name": "Basic LLM Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1824,
        112
      ],
      "parameters": {
        "text": "=You are a lead qualification assistant.\n\nAnalyze the following company data and assign a lead score (0\u2013100) based on business size, relevance, and likelihood to convert.\nReturn only a valid JSON object with this structure:\n{\n  \"summary\": \"...\",\n  \"score\": <number>,\n  \"factors\": [\"...\", \"...\", \"...\"]\n}\n\nCompany data:\nData:\\n{{JSON.stringify($json, null, 2)}}\n",
        "batching": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "79631043-020d-4426-959e-3ecfd6c4cb68",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1760,
        368
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9f37c8b4-212a-4ce6-b22c-d8c55b7fb18c",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        2032,
        352
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"summary\": \"xyz is a mid-sized IT services company with 100 employees and a strong online presence.\",\n  \"score\": 85,\n  \"factors\": [\n    \"Founded in 0000 with proven stability\",\n    \"Active in B2B software services\",\n    \"Good growth potential\"\n  ]\n}\n"
      },
      "typeVersion": 1.3
    },
    {
      "id": "1011600a-e752-4781-af74-64ab31a5cc52",
      "name": "IF - Qualified Lead",
      "type": "n8n-nodes-base.if",
      "position": [
        2288,
        96
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e51c1286-0319-4d84-9296-66c03e69ddb0",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.output.score }}",
              "rightValue": 80
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "02920909-b401-40a1-9b6f-111b77ff6551",
      "name": "Update Lead status - Qualified",
      "type": "n8n-nodes-base.zohoCrm",
      "position": [
        2624,
        -16
      ],
      "parameters": {
        "leadId": "={{ $('Get many leads').item.json.id }}",
        "resource": "lead",
        "operation": "update",
        "updateFields": {
          "Lead_Status": "\"Qualified\""
        }
      },
      "credentials": {
        "zohoOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "68e92c4b-5c9a-4429-8c81-f3dfe100c74e",
      "name": "Update Lead status - NOT qualified",
      "type": "n8n-nodes-base.zohoCrm",
      "position": [
        2640,
        256
      ],
      "parameters": {
        "leadId": "={{ $('Zoho: Get All Leads via API').item.json.data[0].id }}",
        "resource": "lead",
        "operation": "update",
        "updateFields": {
          "Lead_Status": "\"Not Qualified\""
        }
      },
      "credentials": {
        "zohoOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e4b103f6-87bb-4c35-b9e4-e12b89a16068",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 294,
        "height": 288,
        "content": "##  Schedule Trigger\nRuns every X minutes to poll Zoho CRM for new leads."
      },
      "typeVersion": 1
    },
    {
      "id": "67d6250c-879d-4931-8e52-4e7fec27ea98",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1280,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 208,
        "height": 144,
        "content": "## Get website name\n Get the website name of filtered leads\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d0910575-8030-49df-bb23-dfac2e03af45",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1488,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 240,
        "content": "## Enrich Lead (People Data Labs HTTP Request)\nCalls the People Data Labs Company Enrichment API using the extracted domain and extract data\n"
      },
      "typeVersion": 1
    },
    {
      "id": "5fee8aea-1383-4bc4-b025-1a3f87bb5420",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1808,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 176,
        "content": "## Google Gemini (Basic LLM Chain)\nGenerates AI-based lead qualification summary and score (0\u2013100).\nOutputs summary, score, factors."
      },
      "typeVersion": 1
    },
    {
      "id": "c304ab59-151a-41bc-a1e8-4696d5b430bd",
      "name": "send mail for verified lead",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2896,
        -16
      ],
      "parameters": {
        "sendTo": "",
        "message": "=Hi Team,\n\nA new lead has been marked as QUALIFIED by the AI Lead Scoring System. \n\nLead Details:\n\u2022 Name: {{ $('Code in JavaScript').item.json.First_Name }}\n\u2022 Company: {{ $('Code in JavaScript').item.json.Company }}\n\u2022 Email: {{ $('Code in JavaScript').item.json.Email }}\n\u2022 Score: {{ $('IF - Qualified Lead').item.json.output.score }}\nSummary: {{ $('IF - Qualified Lead').item.json.output.summary }}\nYou can view the lead directly in Zoho CRM for more details. \n\n- AI Lead Qualification System",
        "options": {},
        "subject": "=New Qualified Lead:{{ $('Enrich Lead (PDL)').item.json.name }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "307c5464-f2c6-45c9-8b6c-024b8188c140",
      "name": "Get many leads",
      "type": "n8n-nodes-base.zohoCrm",
      "position": [
        480,
        0
      ],
      "parameters": {
        "options": {},
        "resource": "lead",
        "operation": "getAll",
        "returnAll": true
      },
      "credentials": {
        "zohoOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d8072906-be08-43ff-aaa1-15d3c36dce5b",
      "name": "Sticky Note14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -512,
        -816
      ],
      "parameters": {
        "width": 656,
        "height": 704,
        "content": "## Workflow Overview \n**How It Works** \nThis workflow automatically checks Zoho CRM every X minutes, detects newly-created leads, enriches them using People Data Labs, and then uses Google Gemini to generate an AI-based qualification score (0\u2013100). The score determines whether the lead is considered Qualified or Not Qualified. The workflow then updates the Lead Status in Zoho CRM and sends an email notification for qualified leads. It uses a timestamp-based filter to avoid reprocessing old leads and processes each lead independently through enrichment \u2192 scoring \u2192 CRM update \u2192 optional email notification.\n\n**Setup Steps**\n\nZoho CRM OAuth\nAdd your Zoho OAuth2 credentials and ensure the workflow has access to the Leads module (read + update).\n\nPeople Data Labs API Key\nAdd your PDL API key inside the HTTP Request node header (x-api-key).\n\nGoogle Gemini Credentials\nAttach your Gemini model credentials to the LLM Chain.\n\nEmail Notification (Optional)\nUpdate the Gmail node with your own OAuth credentials and recipient list.\n\nTimezone & Frequency\nEdit the Schedule Trigger interval and confirm the offset (+05:30) in \u201cCompute Last Check\u201d.\n\nField Mapping\nVerify Zoho fields: Lead_Status, Email, Company, First_Name, Last_Name.\n\nTest with 1 Lead\nCreate a test lead in Zoho \u2192 confirm enrichment \u2192 score \u2192 CRM update \u2192 email."
      },
      "typeVersion": 1
    },
    {
      "id": "2fa2340b-b0df-4bb2-816a-13d4e76bd52e",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        -144
      ],
      "parameters": {
        "color": 7,
        "width": 736,
        "height": 512,
        "content": "## I'm a note \nfetches all Zoho leads, calculates the last execution time, and filters only the leads created after that timestamp.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d55de9fc-b409-42ca-b824-831ddaeaf7c8",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2208,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 912,
        "height": 544,
        "content": "## Lead Differentiation\ntakes the AI-generated score and decides whether the lead is qualified or not. IF node decide the qualified and unqualified leads and update the field of that lead as qualified or not qualified, For qualified leads , a gmail notification is sent\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "8bc3364a-a6c5-45ef-8b95-7cff184d1d88",
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get many leads": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "IF - Qualified Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Compute Last Check",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get many leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich Lead (PDL)": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Enrich Lead (PDL)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compute Last Check": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "IF - Qualified Lead": {
      "main": [
        [
          {
            "node": "Update Lead status - Qualified",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Lead status - NOT qualified",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Update Lead status - Qualified": {
      "main": [
        [
          {
            "node": "send mail for verified lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}