# POST /scrape-reviews-api: get Google reviews by Place ID

> POST /scrape-reviews-api returns Google Maps reviews for up to 10 Place IDs per call, with rating filters. The call is synchronous.
>
> Part of the LocalPipe API reference: https://www.localpipe.io/docs/reviews (full reference in one file: https://www.localpipe.io/localpipe-api-docs.md, categories CSV: https://www.localpipe.io/localpipe-business-categories.csv)

## POST /scrape-reviews-api

> ⚠️ **Use `scrape-reviews-api`, not `scrape-reviews`.** `scrape-reviews` is the dashboard's internal function and accepts only a signed-in dashboard session. It returns `{"error":"Unauthorized"}` for every API key, no matter how it's passed. If you get Unauthorized on a reviews call, check the endpoint name before you check your key.

Scrape Google Maps reviews for businesses you already have Place IDs for (returned by `/maps-search` and `/get-scrape-results`). This endpoint is **synchronous** — reviews are returned in the response body.

### Request

```bash
curl -X POST "https://uunrlffonnvmbsstkpze.supabase.co/functions/v1/scrape-reviews-api" \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{"place_ids": ["ChIJ...", "ChIJ..."], "max_reviews": 20, "rating_min": 1, "rating_max": 5}'
```

### Request Fields

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| place_id | string | Either this or `place_ids` | A single Google Place ID. |
| place_ids | string[] | Either this or `place_id` | Up to 10 Place IDs per call. |
| max_reviews | integer | No | Max reviews per business, 1-40 (default 20). Newest first. Values outside 1-40 or non-integers return **400**. |
| rating_min | number | No | Only return reviews with rating >= this (1-5, default 1). |
| rating_max | number | No | Only return reviews with rating <= this (1-5, default 5). |

### Response (200 OK)

```json
{
  "status": "completed",
  "requested": 2,
  "total_reviews": 34,
  "duration_ms": 3120,
  "results": [
    {
      "place_id": "ChIJ...",
      "review_count": 20,
      "reviews": [
        {
          "user_name": "Jane D.",
          "rating": 5,
          "review_text": "Great service, fast turnaround.",
          "review_time": "2 months ago"
        }
      ]
    }
  ]
}
```

### Review fields

| Field | Type | Description |
|-------|------|-------------|
| user_name | string or null | Reviewer display name. |
| rating | number or null | Star rating 1-5, always a JSON number (e.g. `5`, never `"5"`). Also a number in `business-list-api?action=reviews`. Treat `null` as unknown, not 0, when averaging. |
| review_text | string or null | Review body; null for rating-only reviews. |
| review_time | string or null | Relative time as shown on Google (e.g. "2 months ago"), not a timestamp. |

**Notes:**
- Rating filtering is applied after fetching, so a narrow range can return fewer than `max_reviews`.
- A business with no reviews returns `review_count: 0` and an empty array — the call still succeeds.
- Errors: `401` invalid/missing key, `400` missing `place_id` or more than 10 IDs, `429` per-minute limit reached.
- Reviews are not billed as enrichment; the call counts against your normal API request limits.
