# Business lists: list, merge, edit, enrich and clean saved lists

> List your saved Business Lists and act on them through /business-list-api: merge, move, edit and remove companies, enrich a list, clear chains and scrape reviews.
>
> Part of the LocalPipe API reference: https://www.localpipe.io/docs/business-lists (full reference in one file: https://www.localpipe.io/localpipe-api-docs.md, categories CSV: https://www.localpipe.io/localpipe-business-categories.csv)

## GET /list-business-lists

Lists your saved Business Lists so you can see what you already have and feed IDs into `exclude_existing_lists`.

```bash
curl "https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/list-business-lists?limit=100" \
  -H "x-api-key: YOUR_API_KEY"
```

### Query Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| limit | integer | 100 | Lists per page (1-200) |
| offset | integer | 0 | Pagination offset |
| search | string | — | Case-insensitive match on the list name |

### Response

```json
{
  "total_lists": 12,
  "lists": [
    {
      "list_id": "0f1c8a2e-4d3b-4f77-9b2a-1c5f9d8e7a10",
      "name": "Austin Plumbers",
      "keyword": "plumbers",
      "locations": ["Austin, TX"],
      "total_leads": 1843,
      "enrichment_status": "completed",
      "created_at": "2026-09-01T12:04:11.000Z",
      "updated_at": "2026-09-01T12:41:02.000Z"
    }
  ],
  "pagination": { "limit": 100, "offset": 0, "next_offset": null, "has_more": false, "returned": 12 }
}
```

This endpoint is read-only and costs no credits. It counts toward your per-minute request limit.

## /business-list-api (actions on an existing Business List)

One endpoint for everything you can do to a saved list. Every call needs `list_id` (from `GET /list-business-lists`) and your `x-api-key`. Lists that don't belong to your account return `404`. POST calls choose what to do with `action`.

| Action | Method | What it does | Cost |
|--------|--------|--------------|------|
| (none) | GET | List summary: name, total_leads, chain-clearing and review-scrape status | Free |
| `companies` | GET | Paginated companies with company IDs for editing, moving and removal | Free |
| `merge` | POST | Copy all companies from source lists into a destination, optionally moving them | Free |
| `move_companies` | POST | Move selected companies from one source into a destination list | Free |
| `edit_company` | POST | Update fields on one company in a list | Free |
| `remove_companies` | POST | Permanently remove selected companies from a list | Free |
| `enrich` | POST | Sends the list's businesses through enrichment as one job | Same as the enrichment you request (billed per result found, like `/enrich`) |
| `delete` | POST | Permanently deletes the list and its businesses | Free |
| `clean_chains` | POST | Finds (`mode: "preview"`) or removes (`mode: "apply"`) chain / franchise businesses | Free |
| `scrape_reviews` | POST | Starts a background Google review scrape for every business in the list | Free |
| `cancel_reviews` | POST | Stops a running review scrape and clears partial reviews | Free |
| `reviews` | GET | Review scrape progress and the scraped reviews, paginated by business | Free |

Base URL: `https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/business-list-api`

### Read companies and their IDs

`GET /business-list-api?list_id=LIST_ID&action=companies&limit=100&offset=0`

Returns `{ "list_id": "...", "total_companies": 200, "companies": [{ "company_id": "UUID", "place_id": "...", "position": 0, "fields": { "name": "Example", "website": "https://example.com" } }], "pagination": { "limit": 100, "offset": 0, "next_offset": 100 } }`.
Use `company_id` (not Google Place ID) for the actions below. Limit 1-1,000; offset is a non-negative integer. A company copied or moved into another list receives a new company ID; read the destination again. Pagination ends when `next_offset` is null.

### Merge lists into one larger list

`list_id` is an existing destination list; provide 1-50 source list IDs. Sources remain intact by default.

`{ "action": "merge", "list_id": "DESTINATION_UUID", "source_list_ids": ["SOURCE_UUID_1", "SOURCE_UUID_2"], "move": false }`

Set `move: true` to remove source companies after merging. Source lists remain as empty lists, and can be deleted separately. Duplicate Google Place IDs are included once; existing destination details win. Records without a Place ID remain separate. No new search, enrichment, credit charge or refund takes place.

### Move selected companies

`{ "action": "move_companies", "list_id": "DESTINATION_UUID", "source_list_id": "SOURCE_UUID", "company_ids": ["COMPANY_UUID"] }`

Moves 1-1,000 selected companies out of the source list. Companies already present by Place ID are removed from the source without duplicating them in the destination. Original company fields are preserved; destination details win for duplicates.

### Edit a company

`{ "action": "edit_company", "list_id": "LIST_UUID", "company_id": "COMPANY_UUID", "fields": { "name": "Updated business", "website": "https://example.com", "phone_number": "+12125551234" } }`

Editable fields: `name`, `website`, `phone_number`, `full_address`, `city`, `price_level`, `rating` (0-5), `review_count` (non-negative integer), `types` (string array), `latitude` (-90 to 90), `longitude` (-180 to 180). Omitted fields are unchanged; null clears a field except name, which cannot be blank. Company ID, Place ID and ownership cannot be edited. These edits affect the saved list only, not completed enrichment results or Google's listing.

### Remove companies from a list

`{ "action": "remove_companies", "list_id": "LIST_UUID", "company_ids": ["COMPANY_UUID_1", "COMPANY_UUID_2"] }`

Permanently removes 1-1,000 selected companies without deleting the list. List totals update immediately. No credits are refunded.

All merge/move/edit/remove changes are atomic: either the entire request succeeds or nothing changes. Every affected list must belong to your API-key account. Missing lists or companies return `404`; invalid inputs return `400`; lists with an active scrape, review scrape, location scrape or list-view preparation return `409` (retry after completion). These actions do not cancel background work or rewrite existing enriched lists.

Success returns `{ "success": true, "action": "merge", "list_id": "...", "selected_count": 200, "added_count": 180, "removed_count": 0, "duplicate_count": 20, "updated_count": 0, "list_totals": { "DESTINATION_UUID": 500, "SOURCE_UUID": 200 } }`. Counts reflect actual changes. `removed_count` includes source duplicates removed by a move; `updated_count` is 1 for an edit.

### Enrich a list

```bash
curl -X POST "https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/business-list-api" \
  -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" \
  -d '{"action":"enrich","list_id":"LIST_ID","want_email":true,"want_business_email":true,"callback_url":"https://your-server.com/webhook"}'
```

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| want_name | boolean | No (default true) | Find owner names |
| want_email | boolean | No (default true) | Find owner emails (needs want_name) |
| want_phone | boolean | No (default false) | Find owner mobiles (needs want_name) |
| want_business_email | boolean | No (default false) | Find business emails |
| business_email_fallback_only | boolean | No (default false) | Only look for a business email when no owner email is found |
| decision_maker_title | string | No | Target a title instead of the owner, e.g. "Office Manager" |
| count | integer | No | Only enrich the first N businesses (max 100,000) |
| only_with_website | boolean | No (default false) | Skip businesses with no website |
| callback_url | string | No | Webhook for results, same payload as `/enrich` jobs. If omitted, poll instead |

Response `202`: `{ "success": true, "job_id": "...", "total_records": 1843, "status": "pending" }`. Track it with `GET /get-job-status?job_id=...` and fetch rows with `GET /get-job-results?job_id=...`. Each row's `extra_columns` carries the business's Google Place ID, phone and address so you can join results back to the list. Balance and plan rules are the same as `/enrich` (`402` when you can't run the job; a `queued_hold` object when it is accepted but waiting for a top-up).

### Delete a list

```json
{ "action": "delete", "list_id": "LIST_ID" }
```
Response: `{ "success": true, "list_id": "...", "deleted": true }`. This cannot be undone.
Deletion works through the API as well as the dashboard. It removes the saved list and its companies, prevents its source scrape from recreating it, and does not delete existing enriched lists or refund credits.

### Clear chains

```json
{ "action": "clean_chains", "list_id": "LIST_ID", "mode": "preview" }
```
`preview` (default) changes nothing and tells you what would be removed; `apply` removes them. Response: `{ "total_leads", "chains_found", "removed_count", "remaining_count", "by_brand": [{ "brand", "category", "count", "examples" }] }`. `removed_count` is always 0 in preview.

### Scrape Google reviews for a list

```json
{ "action": "scrape_reviews", "list_id": "LIST_ID", "max_per_company": 20, "rating_min": 1, "rating_max": 5 }
```
`max_per_company` 1-100 (default 20); `rating_min` / `rating_max` 1-5. Returns `202` and runs in the background. Starting again while one is running resumes it. Poll:

```bash
curl "https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/business-list-api?list_id=LIST_ID&action=reviews&limit=100&offset=0" \
  -H "x-api-key: YOUR_API_KEY"
```

`review_scrape.status` is `not_started`, `processing`, `completed`, `failed` or `canceled`, with `progress` 0-100. `businesses` is `[{ "place_id", "reviews": [...] }]`, up to 500 per page (`pagination.next_offset` is null on the last page). Businesses with no matching reviews are not listed. For a single business, use `POST /scrape-reviews-api` instead.
