# `cleanse_contact_batch` — Cleanse & Deduplicate Contact Batch

> Part of [CRM Cleanse & Dedupe Edge API](https://crm-cleanse.apikeg.com/llms.txt) (`com.apikeg/crm-cleanse`)

Normalizes emails, international E.164 phones, person names/honorifics, and company legal suffixes across 1-500 CRM records, returning merged canonical uniqueRecords and duplicateClusters.

**Why call instead of DIY:** 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.

- **REST Endpoint:** `POST https://crm-cleanse.apikeg.com/v1/cleanse-contact-batch`
- **MCP Server:** `https://crm-cleanse.apikeg.com/mcp` (tool: `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)
- **Free Dry-Run:** `POST https://crm-cleanse.apikeg.com/v1/cleanse-contact-batch?dry_run=true`

## 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
```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 output: 1 unique merged contact and 1 duplicate cluster with exact_email_fingerprint + fuzzy_name_and_company.
