{
  "id": "959H2QjG7f5d1pnW",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Zoho CRM - Social Media Engagement Tracker",
  "tags": [],
  "nodes": [
    {
      "id": "a5614cad-ae75-4fe1-b1db-23cd402e328f",
      "name": "Prepare Contact Data",
      "type": "n8n-nodes-base.function",
      "position": [
        1328,
        560
      ],
      "parameters": {
        "functionCode": "\nconst c = $json;\n\nconst firstName = c.First_Name || c.first_name || '';\nconst lastName  = c.Last_Name  || c.last_name  || '';\nconst company   = (c.Account_Name && c.Account_Name.name) || c.Company || '';\nconst email     = c.Email || c.email || '';\nconst company_id = c.Account_Name.id\n\nreturn [{\n  json: {\n    first_name: firstName,\n    last_name: lastName,\n    full_name: `${firstName} ${lastName}`.trim(),\n    company,\n    email,\n    // keyword for GNews/Reddit\n    keyword: `${firstName}${lastName}${company}`.trim(),\n    zoho_contact_id: c.id || c.contact_id || null,\n    zoho_company_id: company_id\n  }\n}];\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a42335ed-ee45-48c1-ae62-4b253a78ef14",
      "name": "PDL Enrichment",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1616,
        560
      ],
      "parameters": {
        "url": "https://api.peopledatalabs.com/v5/person/enrich",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $json.full_name }}"
            },
            {
              "name": "email",
              "value": "={{ $json.email }}"
            },
            {
              "name": "company",
              "value": "={{ $json.company }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "1ce515e2-58e7-436b-b030-26d524b3963d",
      "name": "IF Social Profiles Found",
      "type": "n8n-nodes-base.if",
      "position": [
        1872,
        560
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "85935f9d-580c-439b-8031-ac7ff314481f",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.data?.profiles?.length }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "ee38f2a9-d974-4bfc-8da2-be426e9686ed",
      "name": "Build Social Summary",
      "type": "n8n-nodes-base.function",
      "position": [
        2176,
        320
      ],
      "parameters": {
        "functionCode": "const p = $json;\nconst profiles = [];\n\nif (p.linkedin_url) profiles.push(`LinkedIn: ${p.linkedin_url}`);\nif (p.twitter_url)  profiles.push(`Twitter: ${p.twitter_url}`);\nif (p.facebook_url) profiles.push(`Facebook: ${p.facebook_url}`);\nif (p.github_url)   profiles.push(`GitHub: ${p.github_url}`);\n\nreturn [{\n  json: {\n    ...p,\n    social_summary: profiles.join(' | '),\n    primary_linkedin: p.linkedin_url || ''\n  }\n}];\n"
      },
      "typeVersion": 1
    },
    {
      "id": "4f86cce0-1e17-4708-888c-795fb43327f4",
      "name": "GNews Mentions",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2464,
        320
      ],
      "parameters": {
        "url": "https://gnews.io/api/v4/search",
        "options": {
          "response": {
            "response": {}
          }
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "={{ $('Prepare Contact Data').item.json.keyword }}"
            },
            {
              "name": "lang",
              "value": "en"
            },
            {
              "name": "apikey"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "0427b9e2-8908-48cf-98f6-3aff0711f4da",
      "name": "Reddit Mentions",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2736,
        320
      ],
      "parameters": {
        "url": "https://www.reddit.com/search.json",
        "options": {
          "response": {
            "response": {}
          }
        },
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "={{ $('Prepare Contact Data').item.json.keyword }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "n8n-social-intel-workflow/1.0"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "a08365e6-67f7-40d5-b718-0148878b9990",
      "name": "Combine Mentions & Score",
      "type": "n8n-nodes-base.function",
      "position": [
        3008,
        320
      ],
      "parameters": {
        "functionCode": "// Expect GNews response shape: { articles: [...] }\n// Reddit response shape: { data: { children: [...] } }\nconst input = $json;\n\nlet news_mentions = [];\nif (input.articles && Array.isArray(input.articles)) {\n  news_mentions = input.articles.map(a => ({\n    source: a.source?.name || 'news',\n    title: a.title,\n    snippet: a.description || a.content || '',\n    url: a.url || null,\n    type: 'news',\n    likes: 0,\n    comments: 0,\n    shares: 0,\n  }));\n}\n\nlet reddit_mentions = [];\nif (input.data && Array.isArray(input.data.children)) {\n  reddit_mentions = input.data.children.map(c => {\n    const d = c.data || {};\n    return {\n      source: `r/${d.subreddit}`,\n      title: d.title,\n      snippet: d.selftext || '',\n      url: d.url || null,\n      type: 'reddit',\n      likes: d.score || 0,\n      comments: d.num_comments || 0,\n      shares: 0,\n    };\n  });\n}\n\nconst mentions = [...news_mentions, ...reddit_mentions];\n\nlet score = 0;\nscore += news_mentions.length * 3;\nreddit_mentions.forEach(r => {\n  score += (r.likes || 0) * 0.5;\n  score += (r.comments || 0) * 1;\n});\n\nreturn [{\n  json: {\n    ...input,\n    mentions,\n    news_mentions,\n    reddit_mentions,\n    engagement_score: score,\n    mention_count: mentions.length\n  }\n}];\n"
      },
      "typeVersion": 1
    },
    {
      "id": "07369290-a322-4e49-9ad7-1f9f08224347",
      "name": "IF High Engagement",
      "type": "n8n-nodes-base.if",
      "position": [
        3280,
        320
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "4ece3c10-313d-44ef-a40b-291973f4a533",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.engagement_score }}",
              "rightValue": 200
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "4d26e724-15cf-4b99-b290-ae8494220b0a",
      "name": "Zoho CRM Create Deal",
      "type": "n8n-nodes-base.zohoCrm",
      "position": [
        3696,
        128
      ],
      "parameters": {
        "stage": "Qualification",
        "dealName": "={{ 'Social Opportunity - ' + ($('Prepare Contact Data').item.json.full_name || 'Unknown') }}",
        "resource": "deal",
        "additionalFields": {}
      },
      "credentials": {
        "zohoOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f2b26edf-cf6c-4940-962a-44652e3b4780",
      "name": "Add Contact and Account Details In Created Deal",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3952,
        128
      ],
      "parameters": {
        "url": "=https://www.zohoapis.com/crm/v2/Deals/{{ $json.id }}",
        "method": "PUT",
        "options": {},
        "jsonBody": "={\n  \"data\": [\n    {\n      \"Contact_Name\": {\n        \"id\": \"{{ $('Prepare Contact Data').item.json.zoho_contact_id }}\"\n      },\n      \"Account_Name\": {\n        \"id\": \"{{ $('Prepare Contact Data').item.json.zoho_company_id }}\"\n      }\n    }\n  ]\n}\n",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "zohoOAuth2Api"
      },
      "credentials": {
        "zohoOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "7a0b4207-2c1d-462e-a27e-8db9d85d7be3",
      "name": "Create Note",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4240,
        128
      ],
      "parameters": {
        "url": "https://www.zohoapis.com/crm/v2/Notes",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"data\": [\n    {\n      \"Note_Title\": \"Social Intelligence Log\",\n      \"Note_Content\": \"Auto-note: Engagement Score:{{ $('Combine Mentions & Score').item.json.engagement_score }},Mentions: {{ $('Combine Mentions & Score').item.json.mention_count }}\",\n      \"Parent_Id\": {\n        \"id\": \"{{ $('Zoho CRM Create Deal').item.json.id }}\"\n      },\n      \"se_module\": \"Deals\"\n    }\n  ]\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "zohoOAuth2Api"
      },
      "credentials": {
        "zohoOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "23063dbd-fe7c-4f4c-8ba8-71b6d5b18ba7",
      "name": "Zoho CRM Update Contact",
      "type": "n8n-nodes-base.zohoCrm",
      "position": [
        3968,
        544
      ],
      "parameters": {
        "resource": "contact",
        "contactId": "={{ $('Prepare Contact Data').item.json.zoho_contact_id }}",
        "operation": "update",
        "updateFields": {
          "customFields": {
            "customFields": [
              {
                "value": "={{ \n  ($('PDL Enrichment').item.json.data.profiles || [])\n    .map(p => p.url)\n    .filter(u => u)\n    .join('\\n')\n}}\n",
                "fieldId": "Social_Profiles"
              },
              {
                "value": "={{ $json.engagement_score >= 50 ? 'Hot' : ($json.engagement_score >= 20 ? 'Warm' : 'Low') }}",
                "fieldId": "Social_Status"
              },
              {
                "value": "={{ $('Combine Mentions & Score').item.json.engagement_score.round() }}",
                "fieldId": "Engagement_Score"
              },
              {
                "value": "={{ $('Combine Mentions & Score').item.json.mention_count }}",
                "fieldId": "Mentions_Counts"
              }
            ]
          }
        }
      },
      "credentials": {
        "zohoOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4a05fd94-8ed5-438c-9d12-51296ee63c4b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 624,
        "height": 448,
        "content": "## Zoho CRM \u2013 Social Media Engagement Tracker\n**How it Works**\nWorkflow triggers from a Zoho CRM webhook whenever a Contact is created/updated.\nIt fetches the Contact details, enriches social profiles via People Data Labs, checks for public mentions (News + Reddit), calculates an engagement score, and updates CRM fields.\nIf the score crosses the threshold, it creates an Opportunity and logs insights automatically.\n\n**Setup steps**\n1. Add Zoho OAuth2 Credentials\n\n2. Set Webhook URL inside Zoho CRM \u2192 Contacts module\n\n3. Add PDL API Key + GNews Key\n\n4. Add custom fields exist on Contacts: Social_Profiles, Engagement_Score, Mentions_Counts , Social_Status\n\n9. Test with a Contact that has public profiles + mentions"
      },
      "typeVersion": 1
    },
    {
      "id": "4aa00983-b172-4f56-8f3e-e8166185b4d7",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        752,
        432
      ],
      "parameters": {
        "color": 7,
        "width": 736,
        "height": 320,
        "content": "## Contact Intake & Preparation\n\nReceives Zoho ContactID and loads full details from CRM. Extracts name, email, company, CRM Contact and Company IDs and builds the search keyword."
      },
      "typeVersion": 1
    },
    {
      "id": "70219fee-72d1-4fb1-861f-dbd0e8b4cf4d",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        432
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 320,
        "content": "## Enrichment\nFetches social profile metadata and stops early if none found."
      },
      "typeVersion": 1
    },
    {
      "id": "c4f30298-6cd9-4623-8dd5-242ae2866a6d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2112,
        160
      ],
      "parameters": {
        "color": 7,
        "width": 784,
        "height": 320,
        "content": "## Public Mention Mining\nQueries news + Reddit using the combined keyword derived from the contact."
      },
      "typeVersion": 1
    },
    {
      "id": "a0e4e533-c3d0-4548-be26-ce61ad0dbebf",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2928,
        160
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 320,
        "content": "## Scoring & Opportunity Check\nMerges mentions, scores & identifies high-value opportunities."
      },
      "typeVersion": 1
    },
    {
      "id": "1614a05d-05a6-4771-9301-910c379fbf84",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3584,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 800,
        "height": 352,
        "content": "## CRM Actions (If High Engagement Found)\nCreates a new opportunity and logs all social intelligence to the CRM."
      },
      "typeVersion": 1
    },
    {
      "id": "13ae2d0e-5b09-46ea-ad33-c2e9ae26f74c",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3792,
        384
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 352,
        "content": "## Add Details in Zoho CRM\nUpdates Social Profiles, Engagement Score, Status, and Mention Count."
      },
      "typeVersion": 1
    },
    {
      "id": "e4ca0cf8-3e15-4546-b916-6c0064b04e19",
      "name": "Zoho CRM New Contact Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        816,
        560
      ],
      "parameters": {
        "path": "zoho-crm-new-contact",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "lastNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "90e6f1c8-6302-4f85-8924-81a433d60709",
      "name": "Get Contact By ID",
      "type": "n8n-nodes-base.zohoCrm",
      "position": [
        1072,
        560
      ],
      "parameters": {
        "resource": "contact",
        "contactId": "={{ $json.body.id }}",
        "operation": "get"
      },
      "credentials": {
        "zohoOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "0e65e399-b9ad-4da5-b685-61bc3d712877",
  "connections": {
    "GNews Mentions": {
      "main": [
        [
          {
            "node": "Reddit Mentions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PDL Enrichment": {
      "main": [
        [
          {
            "node": "IF Social Profiles Found",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reddit Mentions": {
      "main": [
        [
          {
            "node": "Combine Mentions & Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Contact By ID": {
      "main": [
        [
          {
            "node": "Prepare Contact Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF High Engagement": {
      "main": [
        [
          {
            "node": "Zoho CRM Create Deal",
            "type": "main",
            "index": 0
          },
          {
            "node": "Zoho CRM Update Contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Zoho CRM Update Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Social Summary": {
      "main": [
        [
          {
            "node": "GNews Mentions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Contact Data": {
      "main": [
        [
          {
            "node": "PDL Enrichment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Zoho CRM Create Deal": {
      "main": [
        [
          {
            "node": "Add Contact and Account Details In Created Deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine Mentions & Score": {
      "main": [
        [
          {
            "node": "IF High Engagement",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Social Profiles Found": {
      "main": [
        [
          {
            "node": "Build Social Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Zoho CRM New Contact Webhook": {
      "main": [
        [
          {
            "node": "Get Contact By ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Contact and Account Details In Created Deal": {
      "main": [
        [
          {
            "node": "Create Note",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}