# People Enrichment API Reference

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

### What it does

Turn one identifier into a full person profile. Send an email, a SHA-256 hashed email, a phone, a LinkedIn URL, or a name plus company domain and get back job title, seniority, department, company firmographics, work and personal email, direct dial and mobile, work history, education and social profiles. Bulk mode enriches up to 100 records per request and only charges for successful matches.

### Use cases

- Enrich inbound form fills in real time so reps see title, company size and phone number before the first call.
- Resolve hashed-email audiences from ad platforms, CDPs and data clean rooms into full contact profiles without ever sending a plaintext email address.
- Clean and complete a stale CRM: enrich lapsed contacts, detect job changes, and fill in missing phone numbers.
- Reverse-lookup an inbound phone call or unknown email to identify who is reaching out and which account they belong to.
- Batch-enrich a CSV of 100k rows by fanning out parallel 100-record calls, paying only for matches.

### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `email` | string | Email address to look up (any one lookup field is sufficient) |
| `phone` | string | Phone number to look up (e.g. "+14155551234") |
| `linkedin` | string | LinkedIn profile URL to look up |
| `facebook` | string | Facebook profile URL |
| `firstName` | string | First name (improves matching when combined with company) |
| `lastName` | string | Last name (improves matching when combined with company) |
| `companyName` | string | Company name for matching |
| `companyDomain` | string | Company website domain for matching |
| `hasWorkEmail` | boolean | Request work email in results |
| `hasPersonalEmail` | boolean | Request personal email in results |
| `hasPrimaryContact` | boolean | Request primary contact info |
| `hasDirectDial` | boolean | Request direct dial number |
| `hasPhone` | boolean | Request phone number |
| `hasPhoneCell` | boolean | Request cell phone number |
| `hasLocalAddress` | boolean | Request local address |

### 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 |
|-------|-------|
| pid | |
| uuid | |
| id | |
| first_name | |
| last_name | |
| full_name | |
| job_title | |
| seniority | |
| department | |
| job_start_date | |
| new_hire | |
| work_email | |
| work_email_history[] → work_email, yyyyqq | |
| personal_email | |
| personal_email_history[] → personal_email, yyyyqq | |
| linkedin_profile | |
| linkedin_headline | |
| linkedin_connection_count | |
| facebook_profile | |
| education[] → school, start_date, end_date, degrees[] | |
| skills[] | |
| interests[] | |
| work_experience[] → title, company, start_date, end_date | |
| salary | |
| gender | |
| person_city | |
| person_state | |
| company_name | |
| company_domain | |
| company_linkedin_profile | |
| company_industry | |
| company_employee_range | |
| company_revenue_range | |
| company_sic4 | |
| company_sic4_description | |
| company_naics | |
| company_naics_description | |
| company_local_city | |
| company_local_state | |
| company_hq_address | |
| company_hq_city | |
| company_hq_state | |
| company_hq_postal | |
| owner | |
| userId | |
| teamId | |
| is_unlocked | |
| updatedAt | |

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

```json
{
  "data": {
    "pid": "abc123",
    "uuid": "string",
    "id": "abc123",
    "first_name": "string",
    "last_name": "string",
    "full_name": "string",
    "job_title": "string",
    "seniority": "string",
    "department": "string",
    "job_start_date": "2025-06-01T12:00:00Z",
    "new_hire": "string",
    "work_email": "user@example.com",
    "personal_email": "user@example.com",
    "linkedin_profile": "string",
    "linkedin_headline": "string",
    "linkedin_connection_count": 0,
    "facebook_profile": "https://example.com",
    "skills[]": "string",
    "interests[]": "string",
    "salary": "string",
    "gender": "string",
    "person_city": "string",
    "person_state": "string",
    "company_name": "string",
    "company_domain": "string",
    "company_linkedin_profile": "string",
    "company_industry": "string",
    "company_employee_range": "string",
    "company_revenue_range": "string",
    "company_sic4": "string",
    "company_sic4_description": "string",
    "company_naics": [],
    "company_naics_description": [],
    "company_local_city": "string",
    "company_local_state": "string",
    "company_hq_address": "string",
    "company_hq_city": "string",
    "company_hq_state": "string",
    "company_hq_postal": "string",
    "owner": "string",
    "userId": "string",
    "teamId": "string",
    "is_unlocked": false,
    "updatedAt": "2025-06-01T12:00:00Z",
    "work_email_history": [
      {
        "work_email": "user@example.com",
        "yyyyqq": "string"
      }
    ],
    "personal_email_history": [
      {
        "personal_email": "user@example.com",
        "yyyyqq": "string"
      }
    ],
    "education": [
      {
        "school": "string",
        "start_date": "2025-06-01T12:00:00Z",
        "end_date": "2025-06-01T12:00:00Z",
        "degrees[]": "string"
      }
    ],
    "work_experience": [
      {
        "title": "string",
        "company": "string",
        "start_date": "2025-06-01T12:00:00Z",
        "end_date": "2025-06-01T12:00:00Z"
      }
    ]
  }
}
```

### POST /contacts/enrich — Enrich Contact

Look up and enrich a single contact by name, email, LinkedIn, or company. Returns enriched data including work email, phone, job title, and company info.

Email Finder fallback (free): If the enriched contact has no work email (or only a personal email like gmail/yahoo), we automatically run Email Finder using `firstName + lastName + companyDomain` (taken from the response, or from your request if missing). The result is merged in as `email`, `work_email`, `email_source: "email_finder"`, and `email_finder` (status, confidence, smtp_result, catch_all). No extra credits.

**Example Request Body:**

```json
{
  "email": "riseiver@hotmail.com",
  "facebook": "http://www.facebook.com/thesandlovers",
  "linkedin": "https://www.linkedin.com/in/marianne-knight-3b111a37",
  "companyName": "abcd",
  "companyDomain": "abcd.com",
  "firstName": "Marianne",
  "lastName": "Knight",
  "hasWorkEmail": false,
  "hasPersonalEmail": true,
  "hasPrimaryContact": false,
  "hasDirectDial": true,
  "hasPhone": true,
  "hasPhoneCell": true,
  "hasLocalAddress": false
}
```

**cURL Example:**

```bash
curl -X POST 'https://bvjmtgaxijpyasjtaqiv.supabase.co/functions/v1/api-gateway' \
  -H 'Content-Type: application/json' \
  -H 'x-amz-security-token: YOUR-API-KEY' \
  -d '{
  "path": "/contacts/enrich",
  "method": "POST",
  "body": {
    "email": "riseiver@hotmail.com",
    "facebook": "http://www.facebook.com/thesandlovers",
    "linkedin": "https://www.linkedin.com/in/marianne-knight-3b111a37",
    "companyName": "abcd",
    "companyDomain": "abcd.com",
    "firstName": "Marianne",
    "lastName": "Knight",
    "hasWorkEmail": false,
    "hasPersonalEmail": true,
    "hasPrimaryContact": false,
    "hasDirectDial": true,
    "hasPhone": true,
    "hasPhoneCell": true,
    "hasLocalAddress": false
  }
}'
```

### POST /contacts/enrich — Lookup by Email

Find a contact by their email address. Pass only the email field to perform an email-based lookup. Returns the full enriched profile including job title, company, phone numbers, and social profiles.

**Example Request Body:**

```json
{
  "email": "johndoe@example.com"
}
```

**cURL Example:**

```bash
curl -X POST 'https://bvjmtgaxijpyasjtaqiv.supabase.co/functions/v1/api-gateway' \
  -H 'Content-Type: application/json' \
  -H 'x-amz-security-token: YOUR-API-KEY' \
  -d '{
  "path": "/contacts/enrich",
  "method": "POST",
  "body": {
    "email": "johndoe@example.com"
  }
}'
```

### POST /contacts/enrich — Lookup by Phone

Find a contact by their phone number. Pass only the phone field to perform a phone-based lookup. Returns the full enriched profile including name, email, job title, company, and social profiles.

Phone format: The upstream dataset stores US phones as `"(XXX) XXX-XXXX"` (parentheses + space + dash). The API auto-normalizes any input you send — `+14155551234`, `14155551234`, `4155551234`, `415-555-1234`, `415.555.1234` are all accepted and converted server-side. Non-US numbers are passed through unchanged.

**Example Request Body:**

```json
{
  "phone": "(415) 555-1234"
}
```

**cURL Example:**

```bash
curl -X POST 'https://bvjmtgaxijpyasjtaqiv.supabase.co/functions/v1/api-gateway' \
  -H 'Content-Type: application/json' \
  -H 'x-amz-security-token: YOUR-API-KEY' \
  -d '{
  "path": "/contacts/enrich",
  "method": "POST",
  "body": {
    "phone": "(415) 555-1234"
  }
}'
```

### POST /contacts/enrich — Lookup by LinkedIn

Find a contact by their LinkedIn profile URL. Pass only the linkedin field to perform a LinkedIn-based lookup. Returns the full enriched profile including email, phone, job title, and company info.

**Example Request Body:**

```json
{
  "linkedin": "https://www.linkedin.com/in/johndoe"
}
```

**cURL Example:**

```bash
curl -X POST 'https://bvjmtgaxijpyasjtaqiv.supabase.co/functions/v1/api-gateway' \
  -H 'Content-Type: application/json' \
  -H 'x-amz-security-token: YOUR-API-KEY' \
  -d '{
  "path": "/contacts/enrich",
  "method": "POST",
  "body": {
    "linkedin": "https://www.linkedin.com/in/johndoe"
  }
}'
```

### POST /v1/enrich/hashed-email — Lookup by Hashed Email

Privacy-safe enrichment from a SHA-256 hashed email address — no plaintext email ever leaves your systems. Ideal for resolving hashed audiences from ad platforms, CDPs and data clean rooms.

How to build the hash: lowercase and trim the email, then take the SHA-256 hex digest (64 lowercase hex characters). Example: `sha256("test@example.com")` = `973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b`.

Accepted body keys: `hashedEmail` (preferred), `hashed_email`, `hash`, `sha256`, `emailHash`. An invalid or non-64-hex value returns HTTP 400.

Response: the same full profile shape as `/contacts/enrich` (identity, title, seniority, department, emails, mobile and work phones, work history, education, skills, company firmographics). Returns an empty object `{}` when there is no match.

Pricing: 1 credit per successful match. No charge on a miss. Results are cached, so repeat lookups of the same hash are instant.

**Example Request Body:**

```json
{
  "hashedEmail": "973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b"
}
```

**cURL Example:**

```bash
curl -X POST 'https://bvjmtgaxijpyasjtaqiv.supabase.co/functions/v1/api-gateway' \
  -H 'Content-Type: application/json' \
  -H 'x-amz-security-token: YOUR-API-KEY' \
  -d '{
  "path": "/v1/enrich/hashed-email",
  "method": "POST",
  "body": {
    "hashedEmail": "973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b"
  }
}'
```

### POST /bulk-contact-enrich — Bulk Enrich Contacts (up to 100)

Enrich up to 100 contacts in a single synchronous request. Pass the array under the `contacts` key (NOT `records`). Each contact must include at least one identifier (email, linkedin, or phone). Charges 1 credit per successfully enriched contact only — no charge for no_match, skipped, failed, or timeout. If your workspace has fewer credits than the batch size, the excess contacts are returned with status 'skipped' (no charge).

Latency contract (`deadline_ms`) — built for waterfall callers with a fixed client timeout. Default is a hard 1,800 ms server-side wall clock: whatever finished by the deadline is returned, and anything still in flight comes back with `status: "timeout"` and is never charged, so you always get a response instead of a hung socket. Send `deadline_ms` (500–25000) to widen it, or `deadline_ms: 0` to disable the deadline and wait for every record. `timeout_ms` is accepted as an alias.

Response caching: identifier lookups (matches AND misses) are cached, so repeat traffic for the same profile returns in ~250-500 ms server-side. `cache_hits` in the response tells you how many rows were served from cache. Cached rows still cost 1 credit when they are a match.

Phone format: Upstream expects US phones as `"(XXX) XXX-XXXX"`. The endpoint auto-normalizes any input — `+14155551234`, `14155551234`, `4155551234`, `415-555-1234`, `415.555.1234` all work and are converted server-side before lookup. Non-US numbers are passed through unchanged.

Match filters (optional booleans): hasWorkEmail, hasPersonalEmail, hasPrimaryContact, hasDirectDial, hasPhone, hasPhoneCell, hasLocalAddress. Pass at the top level or under `filters` to apply to every contact; pass on a contact object to override for that row. At least one filter must be `true` — sending all `false` returns 400 because the upstream cannot match any record. Omit `filters` entirely to use sensible inferred defaults per contact (e.g. hasPersonalEmail=true when the input has an email). Filters are enforced after the lookup: by default (`matchMode: "all"`) a record that does not carry every requested field is returned as `no_match` and is not charged.

`matchMode` (AND vs OR): `"all"` (default) requires every requested field to exist — so `hasPrimaryContact + hasPhoneCell` only returns records that have both an email and a mobile. Send `"matchMode": "any"` (alias `matchAny: true`) to get the record when at least one requested field exists, e.g. email-or-mobile coverage. `no_match` rows include an `error` naming exactly which requested field(s) were missing, and are never charged. The response echoes `match_mode` and `filters`, plus a `notes` array explaining empty batches (deadline hits, AND semantics, missing identifiers).

`fields` (recommended — fastest and smallest): an array naming only the values you want, e.g. `"fields": ["mobile"]` or `"fields": ["email","mobile"]`. Aliases: `mobile`/`cell` → mobile_number, `phone` → direct_dial + mobile_number + work_number, `email` → work_email + personal_email, plus `work_email`, `direct_dial`, `first_name`, `last_name`, `title`, `company_name`, `company_domain`, `linkedin`. Raw upstream column names also work. Payloads shrink by roughly 80% versus the full profile, and a `fields` list with no email in it skips the work-email discovery step entirely — the single largest source of tail latency. `fields` overrides `fullResponse`.

fullResponse (boolean, default `true`): When `true`, each enriched record returns the complete profile (name, title, company, education, work history, all emails/phones, addresses, etc.). When `false`, each enriched record is slimmed to `contact_id` + every field whose name contains email, phone, mobile, or dial.

Response (flat, NOT nested under `summary`): { total, processed, enriched, no_match, failed, timeout, skipped, cache_hits, credits_used, credits_remaining, response_time_ms, deadline_ms, full_response, fields, results: [{ index, input, status: 'enriched'|'no_match'|'skipped'|'failed'|'timeout', data?, error?, attempts?, cached? }] }.

For jobs larger than 100 records, send multiple batches in parallel or use the async enrichment-jobs flow.

**Example Request Body:**

```json
{
  "filters": {
    "hasWorkEmail": false,
    "hasPersonalEmail": true,
    "hasPrimaryContact": false,
    "hasDirectDial": true,
    "hasPhone": true,
    "hasPhoneCell": true,
    "hasLocalAddress": false
  },
  "fields": [
    "mobile",
    "email"
  ],
  "matchMode": "any",
  "deadline_ms": 2000,
  "contacts": [
    {
      "email": "johndoe@example.com"
    },
    {
      "linkedin": "https://www.linkedin.com/in/janedoe"
    },
    {
      "phone": "(415) 555-1234"
    },
    {
      "firstName": "Alice",
      "lastName": "Smith",
      "companyDomain": "acme.com"
    }
  ]
}
```

**cURL Example:**

```bash
curl -X POST 'https://bvjmtgaxijpyasjtaqiv.supabase.co/functions/v1/bulk-contact-enrich' \
  -H 'Content-Type: application/json' \
  -H 'x-amz-security-token: YOUR-API-KEY' \
  -d '{
  "filters": {
    "hasWorkEmail": false,
    "hasPersonalEmail": true,
    "hasPrimaryContact": false,
    "hasDirectDial": true,
    "hasPhone": true,
    "hasPhoneCell": true,
    "hasLocalAddress": false
  },
  "fields": [
    "mobile",
    "email"
  ],
  "matchMode": "any",
  "deadline_ms": 2000,
  "contacts": [
    {
      "email": "johndoe@example.com"
    },
    {
      "linkedin": "https://www.linkedin.com/in/janedoe"
    },
    {
      "phone": "(415) 555-1234"
    },
    {
      "firstName": "Alice",
      "lastName": "Smith",
      "companyDomain": "acme.com"
    }
  ]
}'
```

### GET /contacts/{contactId} — Get Contact by ID

Retrieve a specific contact's full unlocked profile. {contactId} must be the `pid` returned by POST /contacts/search (not the composite record id). Equivalent to POST /contacts/unlock with a single pid, and billed the same (1 credit).

**cURL Example:**

```bash
curl -X POST 'https://bvjmtgaxijpyasjtaqiv.supabase.co/functions/v1/api-gateway' \
  -H 'Content-Type: application/json' \
  -H 'x-amz-security-token: YOUR-API-KEY' \
  -d '{
  "path": "/contacts/{contactId}",
  "method": "GET"
}'
```

