# POST /location-enrich-api: count a business's locations

> POST /location-enrich-api finds how many physical locations a business operates, from its website and a search fallback. Up to 10,000 businesses per call.
>
> Part of the LocalPipe API reference: https://www.localpipe.io/docs/location-count (full reference in one file: https://www.localpipe.io/localpipe-api-docs.md, categories CSV: https://www.localpipe.io/localpipe-business-categories.csv)

## POST /location-enrich-api

Find out how many physical locations a business operates. We read the company's website (sitemap, store-locator pages, JSON-LD `LocalBusiness` entries, distinct street addresses) and fall back to a Google search when the site is inconclusive. Known large chains and franchises are detected and skipped for free.

This endpoint is **asynchronous** — submit a batch, then poll with the returned `job_id`.

### Request

```bash
curl -X POST "https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/location-enrich-api" \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
        "businesses": [
          { "name": "Joe'''s Plumbing", "website": "joesplumbing.com", "country": "United States" }
        ],
        "callback_url": "https://your-app.com/webhooks/locations"
      }'
```

### Request Fields

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| businesses | array | Yes | Up to 10,000 per call. Each item needs `name` or `website`. |
| businesses[].name | string | — | Business name. |
| businesses[].website | string | — | Website or domain. Strongly improves accuracy. |
| businesses[].country | string | No | Helps disambiguate the search fallback. |
| businesses[].place_id | string | No | Google Place ID, echoed back in results. |
| callback_url | string | No | POSTed when the job completes. |

### Response (202 Accepted)

```json
{
  "status": "processing",
  "job_id": "0f0e2c1a-...",
  "total_businesses": 1200,
  "unique_businesses": 940,
  "cached": 310,
  "billable": 630,
  "estimated_cost_usd": 1.26
}
```

### Poll results

```bash
curl "https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/location-enrich-api?job_id=0f0e2c1a-..." \
  -H "x-api-key: YOUR_API_KEY"
```

```json
{
  "status": "completed",
  "progress": 100,
  "billed_businesses": 630,
  "results": [
    {
      "business_name": "Joe's Plumbing",
      "website": "joesplumbing.com",
      "place_id": "ChIJ...",
      "locations": "14",
      "location_count": 14,
      "count_type": "exact",
      "confidence": "high",
      "source": "site:https://joesplumbing.com/locations"
    }
  ]
}
```

**Notes:**
- `locations` is a display string: an exact count (`"14"`), a range (`"8–12"`), `"100+"`, `"Large chain / franchise"`, or `"Unknown"`.
- Nothing is invented — thin evidence returns `"Unknown"` instead of a guess.
- **Billing: $0.002 per business analysed.** Duplicates within a submission and businesses analysed before (by any account) are free.
