{
  "name": "Find Decision Makers — HubSpot + Apollo",
  "nodes": [
    {
      "parameters": {},
      "id": "manual-trigger",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [0, 0]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.hubapi.com/crm/v3/objects/companies/{{ $json.companyId }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "options": {
          "queryParameters": {
            "parameters": [
              {
                "name": "properties",
                "value": "domain,name,industry,numberofemployees"
              }
            ]
          }
        }
      },
      "id": "fetch-company",
      "name": "Fetch Company",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [220, 0],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apollo.io/api/v1/mixed_people/search",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Api-Key",
              "value": "={{ $credentials.apolloApi.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"q_organization_domains_list\": [\"{{ $('Fetch Company').item.json.properties.domain }}\"],\n  \"person_titles\": [\"VP Sales\", \"CRO\", \"VP Marketing\", \"CMO\", \"VP RevOps\", \"Head of Sales\"],\n  \"person_seniorities\": [\"vp\", \"c_suite\", \"director\"],\n  \"page\": 1,\n  \"per_page\": 25\n}",
        "options": {}
      },
      "id": "search-apollo",
      "name": "Search Apollo",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [440, 0]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "id": "loop-people",
      "name": "Loop People",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [660, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apollo.io/api/v1/people/match",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Api-Key",
              "value": "={{ $credentials.apolloApi.apiKey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"first_name\": \"{{ $json.first_name }}\",\n  \"last_name\": \"{{ $json.last_name }}\",\n  \"organization_name\": \"{{ $json.organization.name }}\",\n  \"reveal_personal_emails\": false\n}",
        "options": {}
      },
      "id": "enrich-person",
      "name": "Enrich Person",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [880, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.hubapi.com/crm/v3/objects/contacts/search",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"filterGroups\": [{\n    \"filters\": [{\n      \"propertyName\": \"email\",\n      \"operator\": \"EQ\",\n      \"value\": \"{{ $json.person.email }}\"\n    }]\n  }]\n}",
        "options": {}
      },
      "id": "check-existing",
      "name": "Check Existing Contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1100, 0],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.total }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "if-new",
      "name": "Is New Contact?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [1320, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.hubapi.com/crm/v3/objects/contacts",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"properties\": {\n    \"email\": \"{{ $('Enrich Person').item.json.person.email }}\",\n    \"firstname\": \"{{ $('Enrich Person').item.json.person.first_name }}\",\n    \"lastname\": \"{{ $('Enrich Person').item.json.person.last_name }}\",\n    \"jobtitle\": \"{{ $('Enrich Person').item.json.person.title }}\",\n    \"company\": \"{{ $('Enrich Person').item.json.person.organization.name }}\",\n    \"hs_lead_status\": \"NEW\"\n  }\n}",
        "options": {}
      },
      "id": "create-contact",
      "name": "Create Contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1540, -100],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "=https://api.hubapi.com/crm/v3/objects/contacts/{{ $json.id }}/associations/companies/{{ $('Fetch Company').item.json.id }}/contact_to_company",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "options": {}
      },
      "id": "associate-contact",
      "name": "Associate with Company",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1760, 0],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [[{ "node": "Fetch Company", "type": "main", "index": 0 }]]
    },
    "Fetch Company": {
      "main": [[{ "node": "Search Apollo", "type": "main", "index": 0 }]]
    },
    "Search Apollo": {
      "main": [[{ "node": "Loop People", "type": "main", "index": 0 }]]
    },
    "Loop People": {
      "main": [
        [{ "node": "Enrich Person", "type": "main", "index": 0 }],
        []
      ]
    },
    "Enrich Person": {
      "main": [[{ "node": "Check Existing Contact", "type": "main", "index": 0 }]]
    },
    "Check Existing Contact": {
      "main": [[{ "node": "Is New Contact?", "type": "main", "index": 0 }]]
    },
    "Is New Contact?": {
      "main": [
        [{ "node": "Create Contact", "type": "main", "index": 0 }],
        [{ "node": "Associate with Company", "type": "main", "index": 0 }]
      ]
    },
    "Create Contact": {
      "main": [[{ "node": "Associate with Company", "type": "main", "index": 0 }]]
    },
    "Associate with Company": {
      "main": [[{ "node": "Loop People", "type": "main", "index": 0 }]]
    }
  },
  "pinData": {},
  "settings": { "executionOrder": "v1" },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "active": false,
  "meta": { "instanceId": "", "templateId": "revi-find-decision-makers" }
}
