{
  "id": "iFap1xHZlQomh35C",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "ICP Report & Lookalike Companies",
  "tags": [],
  "nodes": [
    {
      "id": "699f325b-df7d-44ac-aaf3-9a91bcb66697",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -400,
        464
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "bbf44b30-aeaa-40ab-bda1-67bcfbfe3500",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        400
      ],
      "parameters": {
        "color": 7,
        "width": 1760,
        "height": 544,
        "content": "## get_lookalikes"
      },
      "typeVersion": 1
    },
    {
      "id": "4c059e72-186f-49b5-a463-51fb6ac7e9b0",
      "name": "set_f2",
      "type": "n8n-nodes-base.set",
      "position": [
        848,
        1248
      ],
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "text",
              "stringValue": "={{ $json[\"digest\"] }}"
            }
          ]
        },
        "include": "none",
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "25109522-9d7b-4991-9c24-d724dc29edb8",
      "name": "Filter term.en",
      "type": "n8n-nodes-base.function",
      "position": [
        144,
        1088
      ],
      "parameters": {
        "functionCode": "return items.filter(item => {\n  return item.json.key === 'term.en'\n})\n"
      },
      "typeVersion": 1
    },
    {
      "id": "3adea014-b4cc-4a3e-bcaa-aee5619ba6ab",
      "name": "Filter term.de",
      "type": "n8n-nodes-base.function",
      "position": [
        144,
        1408
      ],
      "parameters": {
        "functionCode": "return items.filter(item => {\n  return item.json.key === 'term.de'\n})\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9ae4bfcc-002e-4b22-8f96-3f2f581c6ce9",
      "name": "parse_term_features",
      "type": "n8n-nodes-base.function",
      "onError": "continueErrorOutput",
      "position": [
        -16,
        1232
      ],
      "parameters": {
        "functionCode": "const newItems = [];\n\nfor (const item of items[0].json.targetProfile.features) {\n  newItems.push({json: item});\n}\n\nreturn newItems;"
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "ecc1ed2c-0b38-4bad-87b9-5c30e3334f0d",
      "name": "merge_terms",
      "type": "n8n-nodes-base.merge",
      "position": [
        688,
        1248
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combinationMode": "multiplex"
      },
      "typeVersion": 2.1
    },
    {
      "id": "a586c5ac-b54b-4246-a87d-60c53065fb6d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        960
      ],
      "parameters": {
        "color": 7,
        "width": 1760,
        "height": 704,
        "content": "## get_icp"
      },
      "typeVersion": 1
    },
    {
      "id": "40aa5f28-d804-463a-8687-6727d7263c5a",
      "name": "Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -400,
        880
      ],
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "explain",
              "type": "booleanValue",
              "booleanValue": "false"
            },
            {
              "name": "size",
              "type": "numberValue",
              "numberValue": "3"
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "cf0858e6-23d0-4aa0-a2b3-a4bab8310f48",
      "name": "Authorization",
      "type": "n8n-nodes-base.set",
      "notes": "Get API key here:\n\nhttps://implisense.com/de/contact",
      "position": [
        -400,
        656
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "x-api-key",
              "value": "XXXX"
            }
          ]
        },
        "options": {}
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "38e00c50-55a0-42c3-b107-37cbc12cf2a8",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1632,
        400
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 1264,
        "content": "## Output"
      },
      "typeVersion": 1
    },
    {
      "id": "39c7181a-ad06-41ef-8103-88b299297e32",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -512,
        400
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 1264,
        "content": "## Input"
      },
      "typeVersion": 1
    },
    {
      "id": "31be4f27-9a5d-4cec-8302-cf54f984ce0f",
      "name": "serialize_ids",
      "type": "n8n-nodes-base.function",
      "position": [
        -16,
        608
      ],
      "parameters": {
        "functionCode": "items[0].json.myVariable = 1;\n\nlet serialization = '';\nfor (const item of items) {\n  serialization += `${item.json.id},`;\n}\n\nreturn [\n  {\n    json: {\n      serialization\n    }\n  }\n];"
      },
      "typeVersion": 1
    },
    {
      "id": "9747ea3f-cc89-4706-9934-dde1979d423a",
      "name": "trim",
      "type": "n8n-nodes-base.set",
      "position": [
        192,
        608
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "serialization",
              "value": "={{ $json.serialization.replace(/[,]/g,'\",\"').trim() }}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 2
    },
    {
      "id": "2ed3cef0-68d2-44eb-81cb-657a96720835",
      "name": "get_lookalikes",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Get your API key here:\n\nhttps://implisense.com/de/contact",
      "maxTries": 2,
      "position": [
        384,
        608
      ],
      "parameters": {
        "url": "=https://api.implisense.com/recommend?explain={{ $('Configuration').item.json.explain }}&size={{ $('Configuration').item.json.size }}",
        "options": {
          "fullResponse": false
        },
        "requestMethod": "POST",
        "jsonParameters": true,
        "bodyParametersJson": "={\n  \"baseCompanies\": [\n    \"{{ $json[\"serialization\"].slice(0,-3) }}\"\n  ],\n  \"locationsFilter\": [\n    {\n      \"type\": \"state\",\n      \"code\": \"de-be\"\n    }\n  ]\n}",
        "headerParametersJson": "="
      },
      "notesInFlow": true,
      "retryOnFail": true,
      "typeVersion": 1,
      "continueOnFail": true,
      "waitBetweenTries": 5000
    },
    {
      "id": "7d433ca2-a8a9-4354-a966-f00303624dc6",
      "name": "lookalikes_or_icp",
      "type": "n8n-nodes-base.switch",
      "position": [
        592,
        608
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "icp",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "53b5f832-e77e-44c8-9986-26160e43ade8",
                    "operator": {
                      "type": "boolean",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Configuration').item.json.explain }}",
                    "rightValue": true
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "f932ee32-7178-4c8f-aa63-88211abe6235",
      "name": "get_companies",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        832,
        624
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "companies"
      },
      "typeVersion": 1
    },
    {
      "id": "b5e8883a-5e2d-46ed-8975-f6d600af6c58",
      "name": "sort_desc",
      "type": "n8n-nodes-base.function",
      "position": [
        336,
        1088
      ],
      "parameters": {
        "functionCode": "const sortedArr = items.sort((a, b) => {\n    let a_name = a.json.targetCount,\n        b_name = b.json.targetCount;\n\n    if (a_name > b_name) {\n        return -1;\n    }\n    if (a_name < b_name) {\n        return 1;\n    }\n    return 0;\n});\nreturn sortedArr;\n"
      },
      "typeVersion": 1
    },
    {
      "id": "3e944979-f230-4f6c-a28a-f18d0e3a1715",
      "name": "digest_terms_en",
      "type": "n8n-nodes-base.function",
      "position": [
        512,
        1088
      ],
      "parameters": {
        "functionCode": "items[0].json.myVariable = 1;\n\nlet digest = '';\nfor (const item of items) {\n  digest += `${item.json.value}: ${item.json.targetCount},\\n`;\n}\n\nreturn [\n  {\n    json: {\n      digest\n    }\n  }\n];"
      },
      "typeVersion": 1
    },
    {
      "id": "5217e2a8-72ea-46bb-af87-27c4bee6b1ce",
      "name": "digest_terms_de",
      "type": "n8n-nodes-base.function",
      "position": [
        512,
        1408
      ],
      "parameters": {
        "functionCode": "items[0].json.myVariable = 1;\n\nlet digest = '';\nfor (const item of items) {\n  digest += `${item.json.value}: ${item.json.targetCount},\\n`;\n}\n\nreturn [\n  {\n    json: {\n      digest\n    }\n  }\n];"
      },
      "typeVersion": 1
    },
    {
      "id": "cc68adf2-41e5-4a38-88a1-02b5062c4cf4",
      "name": "sort_desc2",
      "type": "n8n-nodes-base.function",
      "position": [
        336,
        1408
      ],
      "parameters": {
        "functionCode": "const sortedArr = items.sort((a, b) => {\n    let a_name = a.json.targetCount,\n        b_name = b.json.targetCount;\n\n    if (a_name > b_name) {\n        return -1;\n    }\n    if (a_name < b_name) {\n        return 1;\n    }\n    return 0;\n});\nreturn sortedArr;\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d13b051d-9b5f-4fd3-b3ab-e5997091477b",
      "name": "generate_icp_report",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1040,
        1248
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini",
          "cachedResultName": "GPT-5-MINI"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "={{ $json.text }}"
            },
            {
              "role": "system",
              "content": "=# Regeln\n\n- Nehmen Sie in die Rolle eines Analysten ein, der Unternehmen klassifiziert.\n\nGegeben ist eine Liste von Stichw\u00f6rtern und deren H\u00e4ufigkeiten, die auf verschiedenen Firmenwebsites identifiziert wurden. Diese W\u00f6rter reflektieren zentrale Themen von Unternehmen mit Interesse. Deine Aufgabe ist es, auf Basis dieser Stichw\u00f6rter und ihrer H\u00e4ufigkeiten ein detailliertes Ideal Customer Profile (ICP) zu erstellen. Das ICP sollte Einblicke in die Technologien, Produkte, Bed\u00fcrfnisse der idealen B2B-Kunden geben.\n\nAufgabe:\n\nAnalysiere die Stichw\u00f6rter und ihre Implikationen f\u00fcr ein ICP. Entwickle daraus ein Ideal Customer Profile, das folgende Aspekte umfasst:\n\n1. Technologien: Identifiziere wichtige Technologie-Trends sowie direkte und indirekte Technologien, die diese Unternehmen einsetzen. Fokussiere insbesondere auf moderne Technologien und Technologie-Trends.\n2. Produkte: Leite aus den Stichw\u00f6rtern die Produkte und Services der Unternehmen ab. Erw\u00e4hne die Stichw\u00f6rter und Anzahl der Treffer, um Deine Argumente zu st\u00e4rken.\n3. Bed\u00fcrfnisse: Leite ab, welche Bed\u00fcrfnisse hinter den Interessen der Unternehmen stehen k\u00f6nnten.\n\nNutze diese Informationen, um ein ICP vorzuschlagen, um ideale Kunden zu finden und personalisiert anzusprechen. Generiere im Plaintext Format."
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "092a1a6d-c03e-49e5-9499-a3f952f6cd05",
      "name": "icp_report",
      "type": "n8n-nodes-base.set",
      "position": [
        1744,
        1248
      ],
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "icp_report",
              "stringValue": "={{ $json.output[0].content[0].text }}"
            }
          ]
        },
        "include": "none",
        "options": {
          "ignoreConversionErrors": true
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "a4a127fb-1184-4e6e-95db-4ff7054a5353",
      "name": "list_of_companies",
      "type": "n8n-nodes-base.set",
      "position": [
        1728,
        624
      ],
      "parameters": {
        "values": {
          "number": [
            {
              "name": "crmLeadScore",
              "value": "={{Math.round($json.score * 100)}}"
            }
          ],
          "string": [
            {
              "name": "crmAccountName",
              "value": "={{$json.name}}"
            },
            {
              "name": "crmDomain",
              "value": "={{$json.url}}"
            },
            {
              "name": "crmCity",
              "value": "={{$json.city}}"
            },
            {
              "name": "crmZip",
              "value": "={{$json.zip}}"
            },
            {
              "name": "crmStreet",
              "value": "={{$json.street}}"
            },
            {
              "name": "crmImplisenseId",
              "value": "={{$json.id}}"
            },
            {
              "name": "crmProfileUrl",
              "value": "={{$json.profile}}"
            },
            {
              "name": "crmExplanation",
              "value": "={{$json.explanation}}"
            }
          ],
          "boolean": [
            {
              "name": "crmIsActiveCompany",
              "value": "={{$json.active}}"
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "04c54b5f-27ba-437c-985c-6148e55edec4",
      "name": "\ud83c\udfd7\ufe0f Architecture Notes2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1056,
        400
      ],
      "parameters": {
        "width": 512,
        "height": 1440,
        "content": "# B2B ICP Report & Lookalike Companies in Germany\n\nThis workflow generates a full Ideal Customer Profile (ICP) report and retrieves lookalike companies from the Implisense API. It starts by ingesting a set of base company IDs, serializes them, and sends a recommendation request to Implisense to fetch similar companies. When explanation mode is enabled, the workflow extracts and processes term features to create a structured keyword digest and uses an LLM to generate an ICP narrative. The pipeline outputs both a clean list of lookalike companies, enriched with CRM-ready fields, and a detailed ICP report derived from Implisense feature statistics.\n\n## How it works\n**Input** \u2192 **Serialization** \u2192 **Lookalikes** \u2192 **Lists/Report**\n\n## Setup steps\n\n### 1. Data Source\n\u2610 Replace \"Mock ICP Companies\" with matched companies from the Implisense database\n\u2610 Ensure output has: id\n\n### 2. **Configure Credentials**: Set up RapidAPI API credentials\n   - Get your API key here: https://implisense.com/de/contact\n   - Insert your API Token in get_lookalikes (Basic auth)\n\n### 3. Configure ICP Filters\n\u2610 Edit \"Build Recommendation Request\" node\n\u2610 Set locationsFilter (e.g., de-be, de-by, de-nw)\n\u2610 Set industriesFilter (NACE codes, e.g., J62 for IT)\n\u2610 Set sizesFilter (MICRO, SMALL, MEDIUM, LARGE)\n\n### 4. Tune Results\n\u2610 Adjust THRESHOLD in \"Filter & Normalize Results\" (default: 0.5)\n\u2610 Adjust MIN_BASE_COMPANIES in \"Collect Base Companies\" (default: 3)\n\u2610 Adjust size parameter in \"Configuration\" URL (default: 100)\n\n### 5. CRM Integration\n\u2610 Map fields in \"list_of_companies\" to match your CRM schema\n\u2610 Add CRM upsert node after \"list_of_companies\"\n\u2610 Use implisense-ID or domain as unique identifier\n\n## Additional advice\n\nStrengthen Base Company Quality\nUse only highly representative base companies that strongly match the intended ICP segment. Templates with dozens of mixed or heterogeneous IDs dilute the statistical signal in the /recommend endpoint and reduce relevance.\n\nRefine Filters Aggressively\nLimit recommendations by state, region, NACE code, or size class. Implisense returns cleaner results when the recommendation space is constrained. Removing unnecessary geography broadens noise.\n\nIncrease the Size Parameter\nRaise the size parameter when building the request to give the ranking model more candidates. This materially improves downstream sorting and selection."
      },
      "typeVersion": 1
    },
    {
      "id": "a20d1808-d2a3-4722-b148-9c909b04c978",
      "name": "Mock ICP Companies based on Implisense-ID",
      "type": "n8n-nodes-base.code",
      "position": [
        -400,
        1104
      ],
      "parameters": {
        "jsCode": "return [\n {\n \"id\": [\n\"DEXEF64Q6Q57\",\n\"DEMHMCXXVX35\",\n\"DE94CIJM2285\",\n\"DECXL1MULU53\",\n\"DE44A37AB950\",\n\"DEWX7YLSXD33\",\n\"DENT1AT56A58\",\n\"DE9UMUNCN020\",\n\"DEDEHNP9UC53\",\n\"DEWT7QXQRQ32\",\n\"DECM46M31225\",\n\"DEI2J6FMVZ26\",\n\"DERL98JJ8F78\",\n\"DEC1Y6A0FK62\",\n\"DE1BS1HZU967\",\n\"DE0J7WCH5468\",\n\"DES5IQ9K8M60\",\n\"DE8HQA4XU409\",\n\"DEW5A8SY9V96\",\n\"DEEZZ62FBP42\",\n\"DEG0OAPZ2P91\",\n\"DEKGPZBX0E50\",\n\"DEZ82JE8RX39\",\n\"DEVAY0708427\",\n\"DE0UZ5OFAR95\",\n\"DEC7GHLMW408\",\n\"DEKNFBFHXJ57\",\n\"DEV54N9RH355\",\n\"DE359D7HY984\",\n\"DEADNXAEPO75\",\n\"DEIJAKISPD17\",\n\"DEK7539BP071\",\n\"DEEI80UPMF51\",\n\"DEC6318YME54\",\n\"DEDLY796C977\",\n\"DESGYEATSN08\",\n\"DEYYSTVOLU53\",\n\"DEOIFM53GA57\",\n\"DE4R801G0062\",\n\"DEWKBUVB4W43\",\n\"DESXBBGSL141\",\n\"DE5IW0RPDQ32\",\n\"DEK5L0PKA055\",\n\"DE5QRL004Z42\",\n\"DEFYDJU4GT53\",\n\"DEA1VHLSRB24\",\n\"DEFWE4TZQB44\",\n\"DEUPA9T3GU46\",\n\"DEVF9L9EC003\",\n\"DEYN58WJE381\",\n\"DEOVFS3SLX61\",\n\"DEKSFLSIMH05\",\n\"DEADOZ8Y3957\",\n\"DEPI9ZQUX811\"\n ]\n}\n];"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "12f39f7d-371e-464e-80fe-23ffdf6074e2",
  "connections": {
    "trim": {
      "main": [
        [
          {
            "node": "get_lookalikes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set_f2": {
      "main": [
        [
          {
            "node": "generate_icp_report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "sort_desc": {
      "main": [
        [
          {
            "node": "digest_terms_en",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "icp_report": {
      "main": [
        []
      ]
    },
    "sort_desc2": {
      "main": [
        [
          {
            "node": "digest_terms_de",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "merge_terms": {
      "main": [
        [
          {
            "node": "set_f2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Authorization": {
      "main": [
        [
          {
            "node": "Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configuration": {
      "main": [
        [
          {
            "node": "Mock ICP Companies based on Implisense-ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_companies": {
      "main": [
        [
          {
            "node": "list_of_companies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "serialize_ids": {
      "main": [
        [
          {
            "node": "trim",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter term.de": {
      "main": [
        [
          {
            "node": "sort_desc2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter term.en": {
      "main": [
        [
          {
            "node": "sort_desc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Authorization",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_lookalikes": {
      "main": [
        [
          {
            "node": "lookalikes_or_icp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "digest_terms_de": {
      "main": [
        [
          {
            "node": "merge_terms",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "digest_terms_en": {
      "main": [
        [
          {
            "node": "merge_terms",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "list_of_companies": {
      "main": [
        []
      ]
    },
    "lookalikes_or_icp": {
      "main": [
        [
          {
            "node": "parse_term_features",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "get_companies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "generate_icp_report": {
      "main": [
        [
          {
            "node": "icp_report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "parse_term_features": {
      "main": [
        [
          {
            "node": "Filter term.en",
            "type": "main",
            "index": 0
          },
          {
            "node": "Filter term.de",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mock ICP Companies based on Implisense-ID": {
      "main": [
        [
          {
            "node": "serialize_ids",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}