# E-commerce Data Cleaner & Analyzer (`aidatatools/ecommerce-data-cleaner`) Actor

Turn messy scraper output into clean, deduplicated, calculated reports for AI agents. 90-99% fewer tokens, exact figures, zero hallucination. Detects price anomalies, fake discounts and duplicates. Works with Amazon, AliExpress, eBay, Temu — any dataset. 100% deterministic Python.

- **URL**: https://apify.com/aidatatools/ecommerce-data-cleaner.md
- **Developed by:** [Nicolas Dupuis](https://apify.com/aidatatools) (community)
- **Categories:** E-commerce, AI, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.01 / actor start

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## E-commerce Data Cleaner & Analyzer

Turns raw scraper output into a compact, calculated report ready for AI agents.

**Token reduction on real datasets:**

| Source | Items | Tokens in | Tokens out | Reduction |
|--------|-------|-----------|------------|-----------|
| Amazon Free Scraper | 100 | 1,506,023 | 886 | **99.9%** |
| Amazon Bestsellers | 30 | 27,596 | 687 | **97.5%** |
| AliExpress Scraper | 100 | 25,020 | 1,316 | **94.7%** |
| eBay Scraper | 69 | 10,074 | 1,027 | **89.8%** |

### What it does

- **Field mapping** — normalises field names across scrapers (title/name/productName → name, priceCurrent/$5.59/{value:29.99} → price, etc.)
- **Price normalisation** — handles strings ("US $5.59"), objects ({value: 29.99}), ranges ("$12–$15"), currencies ($, €, £)
- **Anomaly detection** — IQR×1.5, flags price outliers (e.g. a Yamaha piano at $6,499 in a keyboard dataset at $36 median)
- **Fake promo detection** — discount >90% + repeated price + low sales = suspicious (e.g. 6 products at exactly $0.33 with "-95%")
- **Duplicate detection** — exact ASIN match + fuzzy name similarity (rapidfuzz ≥85)
- **Quality ranking** — rating × log(reviews+1); falls back to rating-only when reviews are absent
- **100% deterministic** — no LLM in the pipeline, no hallucination, no random output

### Input

| Field | Required | Description |
|-------|----------|-------------|
| `datasetId` | one of the two | Apify dataset ID from a previous scraper run |
| `rawJson` | one of the two | Raw JSON array of products |
| `apifyToken` | no | Token to access private datasets (defaults to actor account token) |

### Output (single record in dataset)

```json
{
  "source": "apify:abc123",
  "products_analyzed": 100,
  "price_stats": { "median": 43.31, "mean": 119.66, "min": 11.70, "max": 6499.99, ... },
  "conclusions": {
    "cheapest":    { "name": "Amazon Basics Keyboard", "price": 11.70 },
    "best_value":  { "name": "Logitech MK270", "price": 29.99, "score": 52.24 },
    "most_expensive": { "name": "Yamaha 76-Key", "price": 6499.99 }
  },
  "anomalies":            { "count": 5, "rule": "IQR×1.5", "items": [...] },
  "fake_promos_suspects": { "count": 5, "rule": "discount>90% + ≥2 signals", "items": [...] },
  "duplicates":           { "extra_copies_found": 8, "groups": 4, "examples": [...] },
  "_meta": { "tokens_raw": 1506023, "tokens_report": 886, "reduction_pct": 99.9, "cost_saved_usd": 3.76 }
}
```

### Usage with other Apify actors

Chain it directly after any scraper:

1. Run **Amazon Product Scraper** → get `datasetId`
2. Run **E-commerce Data Cleaner** with that `datasetId` as input
3. Your agent receives a 99%+ compressed, analysed report

### MCP server

This actor also ships as an MCP server (`mcp_server.py`) for direct integration with Claude Desktop or any MCP-compatible agent.

# Actor input Schema

## `datasetId` (type: `string`):

Apify dataset ID from a previous scraper run (Amazon, AliExpress, eBay, Temu…). The actor fetches the items automatically.

## `rawJson` (type: `string`):

Raw JSON array (or single object) of products. Use this to test without a prior scraper run.

## `apifyToken` (type: `string`):

Your Apify API token — required only to read private datasets. Leave blank to use the token of the account running the actor.

## Actor input object example

```json
{
  "datasetId": "abc123XYZdatasetId",
  "rawJson": "[{\"title\":\"Wireless Earbuds\",\"price\":{\"value\":29.99,\"currency\":\"$\"},\"stars\":4.5,\"reviewsCount\":1240,\"brand\":\"SoundCo\",\"breadCrumbs\":\"Electronics > Headphones\",\"url\":\"https://example.com/product\"}]"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "rawJson": "[{\"title\":\"Wireless Earbuds\",\"price\":{\"value\":29.99,\"currency\":\"$\"},\"stars\":4.5,\"reviewsCount\":1240,\"brand\":\"SoundCo\",\"breadCrumbs\":\"Electronics > Headphones\",\"url\":\"https://example.com/product\"}]"
};

// Run the Actor and wait for it to finish
const run = await client.actor("aidatatools/ecommerce-data-cleaner").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "rawJson": "[{\"title\":\"Wireless Earbuds\",\"price\":{\"value\":29.99,\"currency\":\"$\"},\"stars\":4.5,\"reviewsCount\":1240,\"brand\":\"SoundCo\",\"breadCrumbs\":\"Electronics > Headphones\",\"url\":\"https://example.com/product\"}]" }

# Run the Actor and wait for it to finish
run = client.actor("aidatatools/ecommerce-data-cleaner").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "rawJson": "[{\\"title\\":\\"Wireless Earbuds\\",\\"price\\":{\\"value\\":29.99,\\"currency\\":\\"$\\"},\\"stars\\":4.5,\\"reviewsCount\\":1240,\\"brand\\":\\"SoundCo\\",\\"breadCrumbs\\":\\"Electronics > Headphones\\",\\"url\\":\\"https://example.com/product\\"}]"
}' |
apify call aidatatools/ecommerce-data-cleaner --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,aidatatools/ecommerce-data-cleaner"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/37fGnnUyMkf5BAEgY/builds/OKhJ27VacSf7cfkCy/openapi.json
