# POST /enrich: find a business owner's name, email and phone

> POST /enrich takes a business name and returns the owner or decision-maker's name, verified email and phone. Request fields, response fields and the webhook payload.
>
> Part of the LocalPipe API reference: https://www.localpipe.io/docs/enrich (full reference in one file: https://www.localpipe.io/localpipe-api-docs.md, categories CSV: https://www.localpipe.io/localpipe-business-categories.csv)

## POST /enrich

Enriches a single business with owner/decision-maker contact information. All requests are **asynchronous** — the API returns a `202 Accepted` response immediately with a `job_id`. Results are delivered via webhook (`callback_url`) or can be polled.

**High-Volume Usage:** You can send thousands of requests simultaneously with a `callback_url` — every request is accepted immediately and queued. Results are delivered to your webhook as each enrichment completes. This is the recommended approach for **Clay** and other automation platforms.

### Request Fields

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| business_name | string | Yes | The name of the business |
| business_website | string | No | The business website (with or without https://). If omitted, the system uses Google Search with the business name and location to find the owner. |
| business_location | string | No | City/state of the business (e.g. "Chicago, IL"). Improves accuracy for multi-location businesses. |
| business_phone | string | No | Recommended when requesting owner phones: supply the business listing phone as a string, preferably with its country code. Aliases: `phone`, `phone_number`. A valid mobile can be returned as `owner_phone` only with `want_phone=true` and an owner name; landlines and ambiguous results are not promoted. |
| want_name | boolean | No | Default: true. **Must be true for owner emails or mobiles**, including when supplying `owner_name` or `business_phone`. Aliases: `want_owner_name`, `find_owner_name`; none may be false when requesting owner contacts. Contradictory requests return HTTP 400 `owner_name_required` without creating a job. Set false only for business-email-only runs. |
| want_email | boolean | No | Whether to find owner email (default: true). Credit plans: 2 credits per found email. Standard owner-search usage billing: $0.015 per found email; custom-title/account rates may differ. |
| want_phone | boolean | No | Whether to find owner phone (default: false). Credit plans: 4 credits per found number. Standard usage billing: $0.03 per found number; custom account rates may differ. |
| want_general_email | boolean | No | Whether to find business email (default: false). General emails are info@, contact@, hello@, etc. Credit plans: 1 credit per found business email. Standard usage billing: $0.005 per found business email; custom account rates may differ. |
| general_email_fallback_only | boolean | No | Only find general business email if owner email is not found (default: false). Requires want_general_email to be true. |
| decision_maker_title | string | No | Target a specific role instead of the business owner (e.g. "Marketing Manager", "Practice Manager"). **If omitted, the system defaults to finding the business owner.** |
| owner_name | string | No | Supply the decision-maker's name yourself (e.g. "Jane Doe", at least 2 words). When provided, name discovery is skipped and contact sourcing uses this name directly. **Not billed** as a name-found credit and **never written to cache** (since it's unverified). Fallback business email logic still applies. |
| clay_row_id | string | No | A passthrough identifier returned unchanged in both the API response and webhook payload. Use this to match results back to rows in Clay or other automation platforms (e.g. `"(/_row_id)"` in Clay). |
| callback_url | string | No | URL to receive results when ready (recommended for Clay and automation platforms). If omitted, poll for results using the job_id. |

```javascript
const response = await fetch("https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/enrich", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": "YOUR_API_KEY"
  },
  body: JSON.stringify({
    business_name: "Acme Corporation",
    business_website: "acme.com",
    business_location: "Chicago, IL",
    business_phone: "+1 202 555 0123", // optional business listing phone
    want_name: true,
    want_email: true,
    want_phone: true,
    want_general_email: true,
    general_email_fallback_only: false,
    decision_maker_title: "Marketing Manager",
    owner_name: "Jane Doe", // optional — skip name discovery and use this name
    clay_row_id: "row_abc123",
    callback_url: "https://your-webhook-url.com/callback"
  })
});
```

**Required for AI agents and developers:** Set `want_name: true` to find owner emails or mobiles. Never send `want_name: false` (or a false name alias) with `want_email: true`, `want_phone: true` or `want_mobile: true`. The API returns HTTP 400 before creating a job:

```json
{
  "error": "owner_name_required",
  "message": "Owner email and owner mobile enrichment require want_name=true. Correct the request and resubmit.",
  "required_parameters": { "want_name": true },
  "job_created": false
}
```

**Phone enrichment recommendation:** Pass `business_phone` from your Google Maps result or CRM and set `want_name: true` and `want_phone: true`. LocalPipe checks it with the existing mobile classification system. Supplying a phone does not enable phone enrichment by itself or prove that the number belongs personally to the owner. Only a valid mobile is eligible; landlines, VoIP, ambiguous results and failed checks are not promoted. Existing cache behavior still applies, and accepted owner-phone results use normal phone-find pricing.

#### Business-email-only example (skip name discovery)

Use this only when you need a general business email. For owner emails or mobiles with an already-known name, supply `owner_name` and keep `want_name: true`; supplied names do not incur a name-find charge.

```javascript
const response = await fetch("https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/enrich", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": "YOUR_API_KEY"
  },
  body: JSON.stringify({
    business_name: "Acme Corporation",
    business_website: "acme.com",
    business_location: "Chicago, IL",
    want_name: false,
    want_email: false,
    want_general_email: true,
    clay_row_id: "row_abc123",
    callback_url: "https://your-webhook-url.com/callback"
  })
});
```

### Response (202 Accepted)

```json
{
  "success": true,
  "job_id": "abc-123",
  "total_records": 1,
  "message": "Request accepted. Record is queued. Results will be POSTed to your callback_url when ready.",
  "estimated_seconds": 30
}
```

### Response Field Reference

> ⚠️ **Field naming — read this before parsing responses.** The exact field names returned in webhook payloads, polling responses, and CSV exports are listed below. **Use these names verbatim in your parser.** A common mistake is looking for `general_email` (does not exist) — the general business email is always returned as `business_email`.

Every record object in `records[]` (webhook payload, polling response, and CSV row) contains exactly these fields:

| Field name (exact) | Type | Description | When populated |
|--------------------|------|-------------|----------------|
| `business_name` | string | Business name (echoed from your request) | Always |
| `business_website` | string | Website (echoed from your request) | Always |
| `business_location` | string | Location (echoed from your request) | Always |
| `owner_name` | string | Decision-maker full name, or `"not found"` | When `want_name=true` (default) |
| `owner_first_name` | string | First name split from `owner_name`, or `"not found"` | Same as `owner_name` |
| `owner_last_name` | string | Last name split from `owner_name`, or `"not found"` | Same as `owner_name` |
| `owner_email` | string | Verified personal email of the decision-maker, or `"not found"` | When `want_email=true` (default) |
| `owner_phone` | string | Decision-maker phone, or `"not found"` | When `want_phone=true` |
| `business_email` | string | **General business email** (`info@`, `contact@`, `hello@`, etc.), or `"not found"` | When `want_general_email=true` |
| `email_provider` | string \| null | Email provider classification for `owner_email` (e.g. `"google"`, `"microsoft"`) | When `owner_email` is found |
| `decision_maker_title` | string \| null | The title that was searched for this row | Multi-title jobs only |
| `owner_role` | string \| null | Role label associated with the decision-maker | When discovered |
| `extra_columns` | object \| null | Passthrough columns from your original request | When provided |

**Negative results are returned literally as the string `"not found"`** — never `null`, never an empty string, never missing. Your parser should treat `"not found"` as "no result for this field".

> **Field name pitfalls — DO NOT use these names, they don't exist:**
> - ❌ `general_email` → ✅ use `business_email`
> - ❌ `generic_email` / `info_email` → ✅ use `business_email`
> - ❌ `personal_email` → ✅ use `owner_email`
> - ❌ `first_name` / `last_name` → ✅ use `owner_first_name` / `owner_last_name`
> - ❌ `phone` / `mobile` → ✅ use `owner_phone`
> - ❌ `name` → ✅ use `owner_name` (and `business_name` for the company)

The request flag is `want_general_email`, but the **returned field is always `business_email`** — the names intentionally differ because the request asks "do you want me to look for it?" and the response key reflects what the value actually is (a generic business mailbox, not the owner's personal email).

### Enrichment Webhook Payload

```json
{
  "job_id": "abc-123",
  "status": "completed",
  "completed_at": "2025-01-01T12:00:00Z",
  "clay_row_id": "row_abc123",
  "stats": {
    "total_records": 1,
    "owner_names_found": 1,
    "owner_emails_found": 1,
    "owner_phones_found": 0,
    "general_emails_found": 1
  },
  "records": [
    {
      "business_name": "Acme Corp",
      "business_website": "acme.com",
      "business_location": "Chicago, IL",
      "owner_name": "John Smith",
      "owner_first_name": "John",
      "owner_last_name": "Smith",
      "owner_email": "john@acme.com",
      "owner_phone": "not found",
      "business_email": "info@acme.com",
      "email_provider": "google",
      "decision_maker_title": null,
      "owner_role": "Owner",
      "extra_columns": null
    }
  ]
}
```

> **Stats field naming:** the count of general business emails in the `stats` object is `general_emails_found` (matches the `want_general_email` request flag), while the per-record field is `business_email`. This is the only place in the response where "general" appears.

> **Email Verification Notice:** Both owner emails (`owner_email`) and business emails (`business_email`) are verified before they are returned, on every plan (credit-based and usage-based). Emails that fail verification come back as `"not found"`, so you do not need to run them through your own checker before sending.

### Parser checklist

Before shipping any merge/import script, confirm:
1. You read `business_email` (not `general_email`) for the generic mailbox.
2. You treat the literal string `"not found"` as an empty value — don't write it into your CRM.
3. You match webhook deliveries back to your rows using `clay_row_id` (the only field guaranteed to round-trip from your request).
4. You handle `owner_email` and `business_email` as separate columns — they are never merged on the API side.

### Enrichment Polling

```bash
curl "https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/get-job-results?job_id=abc-123" \
  -H "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InV1bnJsZmZvbm52bWJzc3RrcHplIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzA0OTIwMzMsImV4cCI6MjA4NjA2ODAzM30.8Ic_U17YrZtsDVnYnIP0XJzrhZJOLDSlJ0AZfTS31FQ"
```
