{
  "id": "j0I1XZANnF7nCozj",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Competitor Client Enrichment & Discovery with PredictLeads",
  "tags": [],
  "nodes": [
    {
      "id": "3034a08d-3447-4906-8ef3-7bdb8b5ca38f",
      "name": "About This Workflow",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1312,
        208
      ],
      "parameters": {
        "color": 4,
        "width": 420,
        "height": 400,
        "content": "ABOUT THIS WORKFLOW\n\nTakes a list of competitor domains, discovers their clients through PredictLeads connections API, enriches each client with company data, and exports everything to Google Sheets.\n\nSetup: Google Sheet with competitor domains, PredictLeads API, Google Sheets OAuth2.\n\nUse case: You want to know who your competitor's customers are. Feed in their domain, and this workflow maps out their client relationships with industry, size, and location data.\n\nPredictLeads API: https://predictleads.com\nQuestions: https://www.linkedin.com/in/yaronbeen"
      },
      "typeVersion": 1
    },
    {
      "id": "601ada32-a658-4666-8c30-24356bd22a47",
      "name": "\ud83d\udccc INPUT",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -768,
        -128
      ],
      "parameters": {
        "color": 5,
        "width": 520,
        "height": 748,
        "content": "## 1\ufe0f\u20e3 Trigger & Competitor Source\n\n**Nodes:**  \n\u25b6\ufe0f Manual Trigger \u2192 \ud83d\udccb Read Competitors\n\n**Description:**  \nThe workflow starts with a manual trigger, allowing the user to run the process whenever competitor analysis is needed.  \nIt reads a list of **competitor company domains** from a Google Sheets watchlist.\n\nThis sheet acts as the source dataset for the discovery process. Each domain represents a competitor whose client relationships will be analyzed using the PredictLeads API."
      },
      "typeVersion": 1
    },
    {
      "id": "25501765-9ac9-42f0-a6f2-c96d21687d16",
      "name": "\ud83d\udd0d DISCOVERY",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        -128
      ],
      "parameters": {
        "color": 5,
        "width": 740,
        "height": 748,
        "content": "## 2\ufe0f\u20e3 Client Discovery from Competitors\n\n**Nodes:**  \n\ud83d\udd04 Loop Competitors \u2192 \ud83d\udd0d Fetch Connections \u2192 \u2699\ufe0f Extract Client Domains\n\n**Description:**  \nEach competitor domain is processed individually using a loop.\n\nThe workflow queries the **PredictLeads Connections API** to retrieve company relationships associated with the competitor.  \nFrom the returned connections data, a code node extracts domains that represent **clients, customers, or users** of the competitor.\n\nThis step transforms raw connection data into a clean list of **potential client companies linked to each competitor**."
      },
      "typeVersion": 1
    },
    {
      "id": "5bb27d7c-675f-4667-a14f-2e3f3197580f",
      "name": "\ud83d\udd0d ENRICHMENT",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        592,
        -176
      ],
      "parameters": {
        "color": 5,
        "width": 740,
        "height": 796,
        "content": "## 3\ufe0f\u20e3 Client Company Enrichment\n\n**Nodes:**  \n\ud83d\udd04 Loop Clients \u2192 \ud83d\udd0d Enrich Client Company \u2192 \u2699\ufe0f Format Output Row\n\n**Description:**  \nEach discovered client domain is processed individually.\n\nThe workflow calls the **PredictLeads Company API** to retrieve detailed company information such as industry, employee count, and location.  \nA code node then formats this enriched data into a structured row that includes:\n\n- Competitor source  \n- Client domain  \n- Client company name  \n- Industry  \n- Employee count  \n- Location  \n\nThis creates a clean dataset ready for reporting or further analysis."
      },
      "typeVersion": 1
    },
    {
      "id": "338cb3da-a85f-4b73-a051-297b26d6d750",
      "name": "\ud83d\udce4 OUTPUT",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1376,
        -80
      ],
      "parameters": {
        "color": 5,
        "width": 400,
        "height": 700,
        "content": "## 4\ufe0f\u20e3 Data Export & Reporting\n\n**Nodes:**  \n\ud83d\udcca Write to Google Sheets\n\n**Description:**  \nThe enriched client data is appended to a **Google Sheets output table**.\n\nEach row represents a discovered client relationship between a competitor and another company, along with key enrichment details.  \nThis sheet becomes a structured dataset for **competitor intelligence, market mapping, and potential lead discovery**."
      },
      "typeVersion": 1
    },
    {
      "id": "5a81d9a0-fa40-4caf-8315-406713cad7e9",
      "name": "\u25b6\ufe0f Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -672,
        400
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "dfeb5d9c-e4d3-45e4-be9d-3391a6b109c9",
      "name": "\ud83d\udccb Read Competitors",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -464,
        400
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID_08/edit#gid=0",
          "cachedResultName": "Competitors"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID_08",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID_08/edit?usp=drivesdk",
          "cachedResultName": "08"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "241d5879-9189-453f-be3d-15afa78275e7",
      "name": "\ud83d\udd04 Loop Competitors",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -112,
        400
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "7ac48d82-4dd0-4d08-825e-c303a2598c48",
      "name": "\ud83d\udd0d Fetch Connections",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        112,
        416
      ],
      "parameters": {
        "url": "=https://predictleads.com/api/v3/companies/{{ $json.domain }}/connections",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Api-Key",
              "value": "YOUR_PREDICTLEADS_API_KEY"
            },
            {
              "name": "X-Api-Token",
              "value": "YOUR_PREDICTLEADS_API_TOKEN"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5543f536-32f3-4cf0-9213-77a311a6ec49",
      "name": "\u2699\ufe0f Extract Client Domains",
      "type": "n8n-nodes-base.code",
      "position": [
        336,
        416
      ],
      "parameters": {
        "jsCode": "// Extract client company domains from connections response\nconst items = $input.all();\nconst clients = [];\n\nfor (const item of items) {\n  const connections = item.json.data || item.json.connections || [];\n  const competitorDomain = item.json.domain || $('\ud83d\udd04 Loop Competitors').item.json.domain || 'unknown';\n\n  for (const conn of connections) {\n    const attrs = conn.attributes || conn;\n    const relationType = (attrs.connection_type || attrs.relationship_type || attrs.type || '').toLowerCase();\n\n    // Include client relationships, or if no type filter, include all connections\n    if (\n      relationType.includes('client') ||\n      relationType.includes('customer') ||\n      relationType.includes('user') ||\n      relationType === ''\n    ) {\n      const clientDomain = attrs.domain || attrs.company_domain || attrs.connected_company_domain || null;\n      if (clientDomain) {\n        clients.push({\n          json: {\n            competitor_source: competitorDomain,\n            client_domain: clientDomain,\n            relationship_type: relationType || 'connection'\n          }\n        });\n      }\n    }\n  }\n}\n\n// If no clients found, pass empty marker\nif (clients.length === 0) {\n  return [{ json: { _no_clients: true, competitor_source: 'N/A' } }];\n}\n\nreturn clients;"
      },
      "typeVersion": 2
    },
    {
      "id": "49dfa78c-8001-4665-9416-6993fcb45c9e",
      "name": "\ud83d\udd04 Loop Clients",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        688,
        416
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "7bbee9ce-1104-438c-b79d-70a17d74e125",
      "name": "\ud83d\udd0d Enrich Client Company",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        928,
        432
      ],
      "parameters": {
        "url": "=https://predictleads.com/api/v3/companies/{{ $('\ud83d\udd04 Loop Clients').item.json.client_domain }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Api-Key",
              "value": "YOUR_PREDICTLEADS_API_KEY"
            },
            {
              "name": "X-Api-Token",
              "value": "YOUR_PREDICTLEADS_API_TOKEN"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f97556ca-dba9-40ba-b800-b047ee66fb3f",
      "name": "\u2699\ufe0f Format Output Row",
      "type": "n8n-nodes-base.code",
      "position": [
        1152,
        432
      ],
      "parameters": {
        "jsCode": "// Format enriched client data into output row\nconst item = $input.first();\nconst companyData = item.json.data?.attributes || item.json.attributes || item.json;\n\n// Get competitor source from the Loop Clients context\nconst competitorSource = $('\ud83d\udd04 Loop Clients').item.json.competitor_source || 'unknown';\nconst clientDomain = $('\ud83d\udd04 Loop Clients').item.json.client_domain || item.json.domain || 'unknown';\n\nreturn [{\n  json: {\n    competitor_source: competitorSource,\n    client_domain: clientDomain,\n    client_name: companyData.company_name || companyData.name || clientDomain,\n    industry: companyData.industry || companyData.sector || 'Unknown',\n    employee_count: companyData.employee_count || companyData.employees || 'Unknown',\n    location: [\n      companyData.city,\n      companyData.state,\n      companyData.country\n    ].filter(Boolean).join(', ') || 'Unknown'\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "7327eaed-b63c-4ae5-bd2b-ea321136ebc4",
      "name": "\ud83d\udcca Write to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1504,
        432
      ],
      "parameters": {
        "columns": {
          "value": {
            "industry": "={{ $json.industry }}",
            "location": "={{ $json.location }}",
            "client_name": "={{ $json.client_name }}",
            "client_domain": "={{ $json.client_domain }}",
            "employee_count": "={{ $json.employee_count }}",
            "competitor_source": "={{ $json.competitor_source }}"
          },
          "schema": [
            {
              "id": "competitor_source",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "competitor_source",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "client_domain",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "client_domain",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "client_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "client_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "industry",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "industry",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "employee_count",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "employee_count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "location",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "location",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1354720506,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID_08/edit#gid=1354720506",
          "cachedResultName": "Client Discovery"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID_08",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID_08/edit?usp=drivesdk",
          "cachedResultName": "08"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "0bb32f2e-eeef-4c45-b8ac-8296a6b248dc",
  "connections": {
    "\ud83d\udd04 Loop Clients": {
      "main": [
        [
          {
            "node": "\ud83d\udd04 Loop Competitors",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "\ud83d\udd0d Enrich Client Company",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u25b6\ufe0f Manual Trigger": {
      "main": [
        [
          {
            "node": "\ud83d\udccb Read Competitors",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udccb Read Competitors": {
      "main": [
        [
          {
            "node": "\ud83d\udd04 Loop Competitors",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd04 Loop Competitors": {
      "main": [
        [],
        [
          {
            "node": "\ud83d\udd0d Fetch Connections",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd0d Fetch Connections": {
      "main": [
        [
          {
            "node": "\u2699\ufe0f Extract Client Domains",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u2699\ufe0f Format Output Row": {
      "main": [
        [
          {
            "node": "\ud83d\udcca Write to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd0d Enrich Client Company": {
      "main": [
        [
          {
            "node": "\u2699\ufe0f Format Output Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udcca Write to Google Sheets": {
      "main": [
        [
          {
            "node": "\ud83d\udd04 Loop Clients",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u2699\ufe0f Extract Client Domains": {
      "main": [
        [
          {
            "node": "\ud83d\udd04 Loop Clients",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}