{
  "id": "rlnRbo8e0S-hqCSRbrtel",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automated AI Lead Enrichment: Hubspot to Explorium for Enhanced Prospect Data",
  "tags": [],
  "nodes": [
    {
      "id": "2e941bac-076e-4c87-970b-cf6cc31cc300",
      "name": "HubSpot Trigger",
      "type": "n8n-nodes-base.hubspotTrigger",
      "position": [
        32,
        -96
      ],
      "parameters": {
        "eventsUi": {
          "eventValues": [
            {}
          ]
        },
        "additionalFields": {}
      },
      "credentials": {
        "hubspotDeveloperApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f379a485-c7f1-4d3e-a3fd-ac799bd69667",
      "name": "HubSpot Recently Created",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        256,
        -96
      ],
      "parameters": {
        "limit": 5,
        "operation": "getRecentlyCreatedUpdated",
        "authentication": "oAuth2",
        "additionalFields": {}
      },
      "credentials": {
        "hubspotOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "907434b1-19d1-419d-9ebc-299e7610486b",
      "name": "Extract Prospect IDs from Matched Results",
      "type": "n8n-nodes-base.code",
      "position": [
        928,
        -96
      ],
      "parameters": {
        "jsCode": "const allItems = $input.all();\nconst prospectIds = allItems.map(item => \n  item.json.matched_prospects.map(prospect => prospect.prospect_id)\n).flat();\n\nreturn [{\n  json: {\n    prospect_ids: prospectIds\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "0be018a0-528c-4359-b800-301119704485",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        1376,
        -96
      ],
      "parameters": {
        "jsCode": "const items = [];\n\nfor (const item of $input.all()) {\n  if (item.json.enriched_data && Array.isArray(item.json.enriched_data)) {\n    for (const enrichedItem of item.json.enriched_data) {\n      items.push({\n        json: {\n          prospect_id: enrichedItem.prospect_id,\n          ...enrichedItem.data\n        }\n      });\n    }\n  }\n}\n\nreturn items;"
      },
      "typeVersion": 2
    },
    {
      "id": "6a0ee2aa-840d-493f-a96c-8837cb62e190",
      "name": "HubSpot Update",
      "type": "n8n-nodes-base.hubspot",
      "position": [
        1600,
        -96
      ],
      "parameters": {
        "email": "={{ $json.professions_email ? $json.professions_email : null }}\n\n\n\n\n\n",
        "options": {},
        "authentication": "appToken",
        "additionalFields": {
          "city": "={{ $json.city ? $json.city : null }}\n",
          "country": "={{ $json.country_name || null }}\n",
          "jobTitle": "={{ $json.experience?.[0]?.title?.levels?.[0] || null }}\n",
          "startDate": "={{ $json.experience && $json.experience[0] && $json.experience[0].start_date ? $json.experience[0].start_date : null }}",
          "workEmail": "={{ $json.professions_email ? $json.professions_email : null }}\n",
          "websiteUrl": "={{ $json.experience?.[0]?.company?.website || null }}\n",
          "companyName": "={{ $json.company_name || null }}\n",
          "phoneNumber": "={{ ($json.phone_numbers?.[1]?.phone_number && $json.phone_numbers[1].phone_number.trim() !== '') ? $json.phone_numbers[1].phone_number : null }}\n",
          "stateRegion": "={{ $json.region_name || '' }}\n",
          "mobilePhoneNumber": "={{ $json.mobile_phone || null }}\n"
        }
      },
      "credentials": {
        "hubspotAppToken": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "9a2e33ca-7ab4-45c8-900c-0efb09b296ca",
      "name": "Filter non-matched",
      "type": "n8n-nodes-base.filter",
      "position": [
        704,
        -96
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "2e6a50ae-51e9-4fd8-ba2d-0c82f83cae6e",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.matched_prospects.some(prospect => prospect.prospect_id !== null).toBoolean() }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "5b60a0bb-8404-4639-83b3-4cb74e56fde5",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        128
      ],
      "parameters": {
        "color": 6,
        "width": 640,
        "height": 620,
        "content": "# Automatically enrich leads in Hubspot using Explorium MCP\n\nThis n8n workflow streamlines the process of enriching prospect information by automatically pulling data from HubSpot, processing it through Explorium's AI-powered tools, and updating the customer's HubSpot account with enhanced prospect details.\n\n## Credentials Required\n\nTo use this workflow, set up the following credentials in your n8n environment:\n\n### HubSpot\n- **Type**: App Token (or OAuth2 for broader compatibility)\n- **Used for**: triggering on new contacts, updating contact records\n\n### Explorium API\n- **Type**: Generic Header Auth\n- **Header**: Authorization\n- **Value**: Bearer YOUR_TOKEN_HERE\n\nGo to Settings \u2192 Credentials, create these two credentials, and assign them in the respective nodes before running the workflow."
      },
      "typeVersion": 1
    },
    {
      "id": "b859589c-60da-4ae6-ad64-00d4fac8e5e1",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        624,
        128
      ],
      "parameters": {
        "color": 4,
        "width": 760,
        "height": 2140,
        "content": "## Workflow Overview\n\n### Node 1: HubSpot Trigger\nThis node listens for real-time events from the connected HubSpot account. Once triggered, the node passes metadata about the event to the next step in the flow.\n\n### Node 2: HubSpot Recently Created\nThis node fetches recently created or updated HubSpot contacts after the trigger event.\n\n- **Credential**: Connected using a HubSpot App Token\n- **Resource**: Contact\n- **Operation**: Get Recently Created/Updated\n- **Limit**: 5 (returns the 5 most recent contact records)\n- **Return All**: Disabled (can be changed to true to retrieve all results)\n\nThis node enriches the initial event (from the Trigger) with full contact details needed for further processing or enrichment.\n\n### Node 3: Explorium Match Prospects\nThis node sends each contact's data to Explorium's AI-powered prospect matching API in real time.\n\n- **Method**: POST\n- **Endpoint**: https://api.explorium.ai/v1/prospects/match\n- **Authentication**: Generic Header Auth (using a configured credential)\n- **Headers**: Content-Type: application/json\n\nThe request body is dynamically built from contact data, typically including: full_name, company_name, email, phone_number, linkedin. These fields are matched against Explorium's intelligence graph to return enriched or validated profiles.\n\n**Response Output**: total_matches, matched_prospects, and a prospect_id. Each response is used downstream to enrich, validate, or update lead information.\n\n### Node 4: Filter (non-matched)\nThis node filters the output from the Explorium Match Prospects step to ensure that only valid, matched results continue in the flow. Only records that contain at least one matched prospect with a non-null prospect_id are passed forward.\n\n### Node 5: Extract Prospect IDs from Matched Results\nThis node extracts all valid prospect_id values from previously matched prospects and compiles them into a flat array. It loops over all matched items, extracts each prospect_id from the matched_prospects array and returns a single object with an array of all prospect_ids.\n\n### Node 6: Explorium Enrich Contacts Information\nThis node performs bulk enrichment of contacts by querying Explorium with a list of matched prospect_ids.\n\n**Before adding this node, validate the destination fields that exist in your HubSpot Account or create them:**\nGo to Settings (gear icon) \u2192 Properties \u2192 Select object type (Contact/Company/Deal/Ticket) \u2192 Create property \u2192 Choose property type \u2192 Enter name & details \u2192 Set permissions \u2192 Create\n\n**Node Configuration:**\n- **Method**: POST\n- **Endpoint**: https://api.explorium.ai/v1/prospects/contacts_information/bulk_enrich\n- **Authentication**: Header Auth (using saved credentials)\n- **Headers**: \"Content-Type\": \"application/json\", \"Accept\": \"application/json\"\n\nReturns enriched contact information, such as:\n- **emails**: professional/personal email addresses\n- **phone_numbers**: mobile and work numbers\n- **professions_email**, **professional_email_status**, **mobile_phone**\n\n### Node 7: Explorium Enrich Profiles\nThis additional enrichment node provides profile-specific data enhancement.\n\n**For adding Profiles enrichment, the following properties should be created in your HubSpot account:**\n- full_name\n- country_name\n- region_name\n- city\n- title\n\n\n### Node 8: Merge\nThis node combines multiple data streams from the parallel enrichment processes (Contacts Information and Profiles) into a single output, allowing you to consolidate data from different Explorium enrichment endpoints. The \"combine\" setting indicates it will merge the incoming data streams rather than overwriting them.\n\n### Node 9: Code (Data Transformation)\nThis custom code node processes and transforms the merged enrichment data before updating HubSpot. It can be used to:\n- Format data according to HubSpot field requirements\n- Apply business logic or data validation\n- Map Explorium fields to HubSpot properties\n- Handle data type conversions\n\n### Node 10: HubSpot Update\nThis final node updates or creates contacts in HubSpot using the enriched data returned by Explorium.\n\n- **Credential**: HubSpot App Token account\n- **Resource**: Contact\n- **Operation**: Create or Update\n\nFor phone numbers, smart fallback logic is applied. This ensures it uses the first phone number if available, otherwise falls back to mobile, or sets \"null\" if none exists.\n\nThis final node writes enriched phone/email info back to HubSpot to ensure the contact record is accurate and complete."
      },
      "typeVersion": 1
    },
    {
      "id": "92100885-63a1-4f98-a25f-27796edf0ab0",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1456,
        128
      ],
      "parameters": {
        "width": 600,
        "height": 588,
        "content": "## Workflow Flow Summary\n\n1. **Trigger**: HubSpot webhook triggers on new/updated contacts\n2. **Fetch**: Retrieve recent contact details from HubSpot\n3. **Match**: Find prospect matches using Explorium\n4. **Filter**: Keep only successfully matched prospects\n5. **Extract**: Compile prospect IDs for bulk enrichment\n6. **Enrich**: Parallel enrichment of contact information and profiles\n7. **Merge**: Combine enrichment results\n8. **Transform**: Final data preparation (Code node)\n9. **Update**: Write enriched data back to HubSpot\n\nThis workflow ensures comprehensive data enrichment while maintaining data quality and providing robust error handling through filtering and validation steps. The streamlined design processes contacts efficiently from HubSpot trigger through to updated records with enriched data."
      },
      "typeVersion": 1
    },
    {
      "id": "98a5b623-07d7-441d-a221-26164784caf5",
      "name": "Match Prospects",
      "type": "@exploriumai/n8n-nodes-explorium-ai.exploriumApiNode",
      "position": [
        480,
        -96
      ],
      "parameters": {
        "type": "prospects",
        "operation": "match",
        "prospects_to_match": {
          "prospects_to_match": [
            {
              "email": "={{ $json['identity-profiles'][0].identities.find(id => id.type === 'EMAIL').value }}"
            }
          ]
        }
      },
      "credentials": {
        "exploriumApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b92aeeb6-cd69-4373-a0c7-b19ba465b3b4",
      "name": "Enrich Prospects",
      "type": "@exploriumai/n8n-nodes-explorium-ai.exploriumApiNode",
      "position": [
        1152,
        -96
      ],
      "parameters": {
        "type": "prospects",
        "jsonInput": "={{ { \"prospect_ids\": $json.prospect_ids } }}",
        "operation": "enrich",
        "enrichment": [
          "contacts",
          "profiles"
        ],
        "useJsonInput": true
      },
      "credentials": {
        "exploriumApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "504b33d5-4497-40ec-a32c-8ad5cd55561f",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "HubSpot Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HubSpot Trigger": {
      "main": [
        [
          {
            "node": "HubSpot Recently Created",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Match Prospects": {
      "main": [
        [
          {
            "node": "Filter non-matched",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich Prospects": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter non-matched": {
      "main": [
        [
          {
            "node": "Extract Prospect IDs from Matched Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HubSpot Recently Created": {
      "main": [
        [
          {
            "node": "Match Prospects",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Prospect IDs from Matched Results": {
      "main": [
        [
          {
            "node": "Enrich Prospects",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}