# B2B Lead Enrichment (Apollo & CRM)

> Enrich leads with Apollo company data in Glow, assign CRM owners by employee count and test how missing or malformed headcounts affect routing.

**Level 2: Routing & AI · about 20 minutes · 5 core steps**

Enrich inbound webhook leads with Apollo company data and assign a CRM owner by employee headcount. Companies over `1000` employees route to Enterprise, `1000` or fewer route to SMB, and missing headcounts stop on **ELSE** for review.

**At a glance**

- **Result:** Enrich a lead with Apollo company data and assign its CRM owner by employee count.
- **You need:** Apollo and CRM connections, enrichment quota, test leads, and destination owners.
- **Usage:** Uses Step credits and Apollo quota (0 Glow AI tokens for the core workflow).
- **What changes:** Runs and action tests query Apollo and update CRM lead fields and owners.

[Webhook](https://docs.getglow.ai/build/triggers/webhook) → Enrichment call → [Conditions](https://docs.getglow.ai/build/action-steps/conditions) → Your CRM

```mermaid
flowchart LR
    W[Webhook: email and crm_lead_id] --> A[Apollo Enrichment]
    A --> C[Conditions: employee_count]
    C -->|Over 1000| E[CRM: Assign Enterprise Owner]
    C -->|1000 or fewer| S[CRM: Assign SMB Owner]
    C -->|ELSE: Missing or Invalid| R[Manual Review Only]
```

## Prerequisites

- **Webhook source:** A form (Typeform, Webflow, or custom) that posts `email` and `crm_lead_id`. You can test with the sample payload first.
- **Apollo.io connection:** Organization enrichment access and available quota.
- **CRM connection:** Permission to update test leads, destination owners, and an existing lead ID per submission. Add a lookup or create Step first if your form omits the ID.

---

## [Building the Automation](https://docs.getglow.ai/getting-started/examples/lead-enrichment-apollo#building-the-workflow)

### 1. The Trigger: Form Submission (Webhook)

Add a **Webhook** trigger and enable **Body only** so fields sit at the top level instead of under `body`. Paste this payload into **Test & Debug → Testing data**:

```json
{
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "crm_lead_id": "replace-with-your-test-lead-id"
}
```

### 2. The Enrichment: Apollo

Add **Apollo.io → Search For Organizations** (pass the domain in **Organization Domains**) or **People Enrichment** (pass **Email** or **Domain**). Keep **Mode** in the `⋮` menu set to **HTTP**. Extract the email domain inline with [Data Transformation](https://docs.getglow.ai/build/core-concepts/data-transformation):

```
{{ 1.email | extract_domain }}
```

Replace `example.com` with an authorized domain. Set the run point to the Webhook trigger and click **Run** in the dock (ordinary **Run step** only replays saved data). Inspect the output to locate the returned employee-count, industry, and revenue fields. An empty response does not mean the company is small.

### 3. The Logic: Condition Step (Routing)

Add a **Conditions** Step with two mutually exclusive **Number** routes. Select the actual employee-count field from **Workflow data** rather than assuming a field name or adding a `ret` wrapper:

  

**Enterprise (Over 1,000)**

    Put two rules in the same condition block (AND): employee count **exists**
    AND **is greater than** `1000`.
  

  

**SMB (1,000 or Fewer)**

    Put two rules in the same condition block (AND): employee count **exists**
    AND **is less than or equal to** `1000`.
  

  

**ELSE (Review Only)**

    Leave **ELSE** disconnected from automated CRM updates, or connect a review
    alert. Blank values or non-numeric strings like `unknown` log a diagnostic
    notice and take **ELSE**.
  

### 4. The Action: CRM Update

**Enterprise CRM Update** (Route 1)

- Add HubSpot → Update Lead or Salesforce → Update Record (Object Type: Lead).
- Map {{ 1.crm_lead_id }}, returned enrichment fields, and the Enterprise owner.

**SMB CRM Update** (Route 2)

- Add a second CRM update Step on the SMB branch with {{ 1.crm_lead_id }}.
- Assign the SMB owner and keep ELSE separate from automatic updates.

> **Handle no match separately from failure:** A call that returns no company
> routes to **ELSE** for review. API failures use an [Error
> Path](https://docs.getglow.ai/build/core-concepts/error-handling). Never substitute an AI estimate
> for a missing headcount.

## Test and go live

Keep the automation in **Draft** pointed at test leads. Set the run point to the Webhook trigger and click **Run** in the dock. To test boundaries (`1001`, `1000`, `999`, blank, absent, `unknown`), temporarily map Conditions to `{{ 1.test_employee_count }}` in the trigger payload, then restore the Apollo field.

| Test case                                                  | Expected result                                                                                      | Where to check                                      |
| :--------------------------------------------------------- | :--------------------------------------------------------------------------------------------------- | :-------------------------------------------------- |
| **Authorized company email + test `crm_lead_id`**          | Enriches `{{ 1.email \| extract_domain }}` and updates the test lead's owner on the matching branch. | Apollo output, Conditions result, and test CRM lead |
| **Boundary check: `1001` vs `1000` and `999`**             | `1001` matches **Enterprise** only; `1000` and `999` match **SMB** only.                             | Conditions route result and test CRM lead owner     |
| **Absent, blank (`""`), or non-numeric (`unknown`) count** | Neither numeric route matches; run takes **ELSE** with 0 CRM updates.                                | Conditions diagnostics and unchanged CRM test lead  |
| **Enrichment returns no company or fails**                 | No-match takes **ELSE**; API failures follow your [Error Path](https://docs.getglow.ai/build/core-concepts/error-handling). | Run history, enrichment output, and CRM lead        |
| **Go Live check: one controlled form submission**          | Live Webhook run enriches the domain and updates the test lead once.                                 | Automation run history and CRM lead                 |

**Verify it works**

- **Run:** Set the Webhook trigger as the starting Step with your test lead payload and click Run in the dock.
- **You should see:** Apollo enriches the domain, Conditions selects the matching headcount branch, and your CRM updates the test lead owner.

## What's Next?

👉 **[Continue to AI Support Router with Tools →](https://docs.getglow.ai/getting-started/examples/ai-customer-support-router)**

- Walk through branching basics in [3. Branching](https://docs.getglow.ai/getting-started/tutorials/lead-routing-tutorial).
- Normalize inbound fields with [Data Transformation](https://docs.getglow.ai/build/core-concepts/data-transformation).
- Add failure recovery with [Error Handling & Retries](https://docs.getglow.ai/build/core-concepts/error-handling).
