# Email Finder API Reference

> Platform documentation snapshot. Access, charging and provider requirements remain operation-specific; examples do not execute requests.

### What it does

Find and validate a work email from a name plus company domain. Returns the best-guess address with confidence, pattern used, SMTP result and catch-all status.

### Use cases

- Recover addresses for prospects that enrichment could not match, before dropping them from a campaign.
- Reconstruct addresses for a target account from a public team or leadership page.
- Validate email pattern assumptions across a domain before sending a large campaign.

### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `first_name` | string | Person's first name. Required. |
| `last_name` | string | Person's last name. Required. |
| `company_domain` | string | Company root domain (e.g. `factori.ai`). Required if `linkedin_url` is not provided. |
| `linkedin_url` | string | LinkedIn URL. Accepts a **person profile** (`https://www.linkedin.com/in/...`) — name + company domain resolved from our profile index — or a **company URL** (`https://www.linkedin.com/company/...`) — domain resolved from our B2B database. |

### Response Schema

_Complete documented fields for this section, with nested notation preserved. Endpoint-specific envelopes, availability and additional fields are described under each endpoint below._

| Field | Notes |
|-------|-------|
| status (found \| guessed \| not_found \| skipped \| no_mx) | |
| email — best deliverable address (when status = found or guessed) | |
| confidence (high \| medium \| low) | |
| smtp_result (valid \| catch-all \| unknown) | |
| catch_all (boolean) — true means domain accepts all mailboxes | |
| company_domain, first_name, last_name | |
| cached (boolean) — true if served from cache | |
| credits_charged — 1 on `found`, 0 otherwise | |
| response_time_ms | |

**Illustrative Example Response (synthetic, not a complete endpoint schema):**

```json
{
  "data": [
    {
      "status": "string",
      "email — best deliverable address": "user@example.com",
      "confidence": "string",
      "smtp_result": "string",
      "catch_all (boolean) — true means domain accepts all mailboxes": "string",
      "company_domain, first_name, last_name": "string",
      "cached (boolean) — true if served from cache": "string",
      "credits_charged — 1 on `found`, 0 otherwise": "string",
      "response_time_ms": "string"
    }
  ],
  "pagination": {
    "page": 1,
    "page_size": 20,
    "total": 1,
    "has_more": false
  },
  "credits_used": 1
}
```

### POST /email-finder — Find Email by Name + Domain

Find the most likely deliverable work email for a person at a company.

Inputs (one of):
- `first_name` + `last_name` + `company_domain`
- `first_name` + `last_name` + `linkedin_url` (company LinkedIn URL — we'll resolve the domain from our B2B database)

How it works:
1. Builds ~10 ranked candidate patterns (`first.last@`, `flast@`, `first@`, etc.).
2. Resolves the domain's MX records.
3. Opens a single SMTP session and probes each candidate via `RCPT TO`, plus a random-string probe to detect catch-all domains.
4. Returns the first definitively valid mailbox, or a low-confidence guess if the domain is catch-all.
5. Result is cached per `(first, last, domain)` so repeat lookups are instant and free.

Auth: `x-amz-security-token: <api_key>` (legacy `Authorization: Bearer <api_key>` also accepted).
Cost: 1 credit per successful find (`status = found`). Catch-all guesses, `not_found`, and cached hits are free.

**Example Request Body:**

```json
{
  "first_name": "Koko",
  "last_name": "Zarov",
  "company_domain": "factori.ai"
}
```

**cURL Example:**

```bash
curl -X POST 'https://bvjmtgaxijpyasjtaqiv.supabase.co/functions/v1/email-finder' \
  -H 'Content-Type: application/json' \
  -H 'x-amz-security-token: YOUR-API-KEY' \
  -d '{
  "first_name": "Koko",
  "last_name": "Zarov",
  "company_domain": "factori.ai"
}'
```

### POST /email-finder — Find Email by LinkedIn URL

Find the work email for a person given only their LinkedIn profile URL.

Pipeline:
1. Detects a person profile URL (`linkedin.com/in/...`).
2. Resolves `first_name`, `last_name`, and `company_domain` from our professional-profile index.
3. Runs the same candidate-pattern + SMTP validation pipeline as the name + domain endpoint.
4. Result is cached per `(first, last, domain)` for instant repeat lookups.

Auth: `x-amz-security-token: <api_key>` (legacy `Authorization: Bearer <api_key>` also accepted).
Cost: 1 credit per request when a valid mailbox is found. Identity resolution is free to you on `not_found`. `resolved_via` in the response is `profile_index` when the profile index supplied the identity, otherwise `direct`.

**Example Request Body:**

```json
{
  "linkedin_url": "https://www.linkedin.com/in/koko-zarov-a54b3061"
}
```

**cURL Example:**

```bash
curl -X POST 'https://bvjmtgaxijpyasjtaqiv.supabase.co/functions/v1/email-finder' \
  -H 'Content-Type: application/json' \
  -H 'x-amz-security-token: YOUR-API-KEY' \
  -d '{
  "linkedin_url": "https://www.linkedin.com/in/koko-zarov-a54b3061"
}'
```

