# CRM Cleanse & Dedupe Edge API (v1.0.0)

> Normalize E.164 phones, clean names/companies, and fuzzy-deduplicate up to 500 CRM leads in <15ms.

Deterministic international E.164 phone parsing (40+ countries), smart name/email/company normalization, free-webmail vs. corporate domain isolation, and Jaro-Winkler + Soundex fuzzy contact deduplication.

## Why Agents Use This API Instead of DIY
Eliminates brittle regexes, trunk-zero E.164 bugs, McDonald/O'Connor casing mistakes, free-webmail false merges, and multi-turn LLM token burn over large lead lists.

## Connection & Payment (x402 Default + Optional Bearer API Key)
- **MCP Server (Streamable HTTP):** `https://crm-cleanse.apikeg.com/mcp` (Registry ID: `com.apikeg/crm-cleanse` — `initialize`, `tools/list`, `resources/*`, and `prompts/*` are free)
- **OpenAPI 3.1 Spec:** [openapi.json](https://crm-cleanse.apikeg.com/openapi.json)
- **Full Schema & Examples:** [llms-full.txt](https://crm-cleanse.apikeg.com/llms-full.txt)
- **RFC 9727 API Catalog:** [.well-known/api-catalog](https://crm-cleanse.apikeg.com/.well-known/api-catalog)
- **x402 Bazaar Manifest:** [.well-known/x402.json](https://crm-cleanse.apikeg.com/.well-known/x402.json)
- **MCP Discovery Manifest:** [.well-known/mcp.json](https://crm-cleanse.apikeg.com/.well-known/mcp.json)
- **A2A Agent Card:** [.well-known/agent-card.json](https://crm-cleanse.apikeg.com/.well-known/agent-card.json)
- **Primary Payment (Zero Signup):** Cloudflare Monetization Gateway (`HTTP 402` / `x402` v2 with USDC on Base).
- **Optional Monthly API Key:** Pass `Authorization: Bearer ak_live_...` ($5 / $20 / $50 monthly per-product Stripe plans at [apikeg.com/account](https://apikeg.com/account)).
- **Free Preflight:** Append `?dry_run=true` (or header `X-Dry-Run: true`) to validate any request payload at `$0.00` cost.

## Tools & REST Endpoints
- [`cleanse_contact_batch`](https://crm-cleanse.apikeg.com/tools/cleanse-contact-batch.md) (`POST https://crm-cleanse.apikeg.com/v1/cleanse-contact-batch`) — $0.001 base (up to $0.01 max ($0.001 minimum + $0.002 per 100 records, capped at $0.01 for up to 500 records), x402 variable settlement): Normalizes emails, international E.164 phones, person names/honorifics, and company legal suffixes across 1-500 CRM records, returning merged canonical uniqueRecords and duplicateClusters.
- [`compare_contact_pair`](https://crm-cleanse.apikeg.com/tools/compare-contact-pair.md) (`POST https://crm-cleanse.apikeg.com/v1/compare-contact-pair`) — $0.0005 USD per contact pair comparison (x402 instant micropayment): Computes field-by-field normalized similarity (email fingerprint, E.164 phone, Jaro-Winkler + Soundex name, company key, corporate domain) and returns an isMatch merge recommendation.

## Instant MCP Configuration
```json
{
  "mcpServers": {
    "crm-cleanse": {
      "type": "streamable-http",
      "url": "https://crm-cleanse.apikeg.com/mcp"
    }
  }
}
```

## Common Agent Use Cases
- deduplicate CRM contacts API
- normalize international phone numbers to E.164 MCP
- fuzzy match HubSpot Salesforce leads Jaro-Winkler
- strip company legal suffixes LLC GmbH Inc API
- cleanse B2B lead list before enrichment

---

## Detailed Tool Specifications

### `cleanse_contact_batch` — Cleanse & Deduplicate Contact Batch
- **REST Endpoint:** `POST https://crm-cleanse.apikeg.com/v1/cleanse-contact-batch`
- **Tool Doc Page:** https://crm-cleanse.apikeg.com/tools/cleanse-contact-batch
- **MCP Tool Name:** `cleanse_contact_batch`
- **Pricing:** $0.001 base (up to $0.01 max ($0.001 minimum + $0.002 per 100 records, capped at $0.01 for up to 500 records), x402 variable settlement)
- **Side Effects:** readOnly=true, idempotent=true, destructive=false
- **Build vs. Buy ROI:** Replaces 300+ lines of fragile phone/name/Jaro-Winkler code and saves thousands of LLM tokens on 500-row CSV imports; executes deterministically in <15ms.

#### Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "records": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "maxLength": 128,
            "description": "Optional caller-supplied CRM record identifier."
          },
          "fullName": {
            "type": "string",
            "maxLength": 200,
            "description": "Full person name (may include honorifics/suffixes such as 'Dr. Ronald MCDONALD, MBA')."
          },
          "firstName": {
            "type": "string",
            "maxLength": 120,
            "description": "Given/first name if already split."
          },
          "lastName": {
            "type": "string",
            "maxLength": 120,
            "description": "Family/last name if already split."
          },
          "email": {
            "type": "string",
            "maxLength": 320,
            "description": "Email address (supports +tag subaddressing and free-webmail detection)."
          },
          "phone": {
            "type": "string",
            "maxLength": 64,
            "description": "Domestic or international phone string, optionally including an extension."
          },
          "country": {
            "type": "string",
            "minLength": 2,
            "maxLength": 2,
            "pattern": "^[A-Za-z]{2}$",
            "description": "Per-record ISO 3166-1 alpha-2 country override for domestic phone parsing."
          },
          "company": {
            "type": "string",
            "maxLength": 240,
            "description": "Raw company or organization name (e.g. 'Acme, Inc.' or 'Siemens AG')."
          },
          "title": {
            "type": "string",
            "maxLength": 160,
            "description": "Job title or organizational role."
          },
          "website": {
            "type": "string",
            "maxLength": 512,
            "description": "Company website URL or domain."
          }
        },
        "additionalProperties": false,
        "description": "CRM contact or lead record."
      },
      "minItems": 1,
      "maxItems": 500,
      "description": "Batch of 1 to 500 CRM contact records to normalize and deduplicate."
    },
    "defaultCountry": {
      "type": "string",
      "default": "US",
      "minLength": 2,
      "maxLength": 2,
      "pattern": "^[A-Za-z]{2}$",
      "description": "Default ISO 3166-1 alpha-2 country code for domestic phone numbers."
    },
    "dedupe": {
      "type": "boolean",
      "default": true,
      "description": "Cluster duplicate records and merge non-null fields into uniqueRecords."
    },
    "matchThreshold": {
      "type": "number",
      "default": 0.82,
      "minimum": 0.5,
      "maximum": 1,
      "description": "Minimum confidence threshold [0.5-1.0] required to merge duplicate records."
    }
  },
  "required": [
    "records"
  ],
  "additionalProperties": false
}
```

#### Examples
**Deduplicate messy international leads** — Merges +tag email and trunk-zero UK/US phone duplicates while isolating Gmail leads.
```bash
curl -X POST "https://crm-cleanse.apikeg.com/v1/cleanse-contact-batch" \
  -H "Content-Type: application/json" \
  -d '{"defaultCountry":"US","dedupe":true,"matchThreshold":0.82,"records":[{"fullName":"Dr. Ronald MCDONALD, MBA","email":"ronald+webinar@ApexCloud.io","phone":"(415) 555-2671 ext. 402","company":"Apex Cloud, Inc."},{"firstName":"Ronald","lastName":"McDonald","email":"ronald@apexcloud.io","company":"Apex Cloud LLC"}]}'
```
Expected result: 1 unique merged contact and 1 duplicate cluster with exact_email_fingerprint + fuzzy_name_and_company.

### `compare_contact_pair` — Compare Two Contacts for Duplicate Match
- **REST Endpoint:** `POST https://crm-cleanse.apikeg.com/v1/compare-contact-pair`
- **Tool Doc Page:** https://crm-cleanse.apikeg.com/tools/compare-contact-pair
- **MCP Tool Name:** `compare_contact_pair`
- **Pricing:** $0.0005 USD per contact pair comparison (x402 instant micropayment)
- **Side Effects:** readOnly=true, idempotent=true, destructive=false
- **Build vs. Buy ROI:** Instant deterministic entity-resolution check for webhook/CRM pre-insert hooks at $0.0005 per pair.

#### Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "recordA": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 128,
          "description": "Optional caller-supplied CRM record identifier."
        },
        "fullName": {
          "type": "string",
          "maxLength": 200,
          "description": "Full person name (may include honorifics/suffixes such as 'Dr. Ronald MCDONALD, MBA')."
        },
        "firstName": {
          "type": "string",
          "maxLength": 120,
          "description": "Given/first name if already split."
        },
        "lastName": {
          "type": "string",
          "maxLength": 120,
          "description": "Family/last name if already split."
        },
        "email": {
          "type": "string",
          "maxLength": 320,
          "description": "Email address (supports +tag subaddressing and free-webmail detection)."
        },
        "phone": {
          "type": "string",
          "maxLength": 64,
          "description": "Domestic or international phone string, optionally including an extension."
        },
        "country": {
          "type": "string",
          "minLength": 2,
          "maxLength": 2,
          "pattern": "^[A-Za-z]{2}$",
          "description": "Per-record ISO 3166-1 alpha-2 country override for domestic phone parsing."
        },
        "company": {
          "type": "string",
          "maxLength": 240,
          "description": "Raw company or organization name (e.g. 'Acme, Inc.' or 'Siemens AG')."
        },
        "title": {
          "type": "string",
          "maxLength": 160,
          "description": "Job title or organizational role."
        },
        "website": {
          "type": "string",
          "maxLength": 512,
          "description": "Company website URL or domain."
        }
      },
      "additionalProperties": false,
      "description": "CRM contact or lead record."
    },
    "recordB": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 128,
          "description": "Optional caller-supplied CRM record identifier."
        },
        "fullName": {
          "type": "string",
          "maxLength": 200,
          "description": "Full person name (may include honorifics/suffixes such as 'Dr. Ronald MCDONALD, MBA')."
        },
        "firstName": {
          "type": "string",
          "maxLength": 120,
          "description": "Given/first name if already split."
        },
        "lastName": {
          "type": "string",
          "maxLength": 120,
          "description": "Family/last name if already split."
        },
        "email": {
          "type": "string",
          "maxLength": 320,
          "description": "Email address (supports +tag subaddressing and free-webmail detection)."
        },
        "phone": {
          "type": "string",
          "maxLength": 64,
          "description": "Domestic or international phone string, optionally including an extension."
        },
        "country": {
          "type": "string",
          "minLength": 2,
          "maxLength": 2,
          "pattern": "^[A-Za-z]{2}$",
          "description": "Per-record ISO 3166-1 alpha-2 country override for domestic phone parsing."
        },
        "company": {
          "type": "string",
          "maxLength": 240,
          "description": "Raw company or organization name (e.g. 'Acme, Inc.' or 'Siemens AG')."
        },
        "title": {
          "type": "string",
          "maxLength": 160,
          "description": "Job title or organizational role."
        },
        "website": {
          "type": "string",
          "maxLength": 512,
          "description": "Company website URL or domain."
        }
      },
      "additionalProperties": false,
      "description": "CRM contact or lead record."
    },
    "defaultCountry": {
      "type": "string",
      "default": "US",
      "minLength": 2,
      "maxLength": 2,
      "pattern": "^[A-Za-z]{2}$",
      "description": "Default ISO 3166-1 alpha-2 country code for domestic phone numbers."
    },
    "matchThreshold": {
      "type": "number",
      "default": 0.82,
      "minimum": 0.5,
      "maximum": 1,
      "description": "Minimum confidence threshold [0.5-1.0] required to recommend merging."
    }
  },
  "required": [
    "recordA",
    "recordB"
  ],
  "additionalProperties": false
}
```

#### Examples
**Compare phonetic surname & legal suffix variants**
```bash
curl -X POST "https://crm-cleanse.apikeg.com/v1/compare-contact-pair" \
  -H "Content-Type: application/json" \
  -d '{"defaultCountry":"GB","matchThreshold":0.82,"recordA":{"fullName":"Jon Smyth","phone":"07911 123456","company":"Albion Analytics Ltd"},"recordB":{"fullName":"John Smith","phone":"+44 7911 123456","company":"Albion Analytics Limited"}}'
```
Expected result: isMatch=true, recommendation='merge' with exact_phone_e164, fuzzy_name_and_company, and phonetic_name_match.
