# MarginDiff | Supplier Feed Auditor + Margin Risk (`001hp/margindiff-supplier-feed-auditor`) Actor

Audit supplier product feeds for pricing errors, negative margins, duplicate SKUs, missing product data, inventory drops, and catalog changes. Compare current and previous CSV or JSON feeds and receive actionable reports in HTML, CSV, and JSON formats.

- **URL**: https://apify.com/001hp/margindiff-supplier-feed-auditor.md
- **Developed by:** [andrew holliday](https://apify.com/001hp) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $490.00 / 1,000 completed feed audits

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## MarginDiff — Supplier Feed Auditor + Margin Risk

**Audit supplier catalogs before they break your product listings or cost you money.**

MarginDiff compares CSV, TSV, or JSON product feeds, flags invalid SKUs/prices, detects low gross margins, and highlights suspicious changes between yesterday's catalog and today's. All processing runs inside an Apify Actor and produces exportable findings.

### What it detects

| Check | Issue code | Description |
|---|---|---|
| Duplicate SKU | `DUPLICATE_SKU` | Duplicate item identifiers (case insensitive) |
| Missing SKU/title | `MISSING_SKU`, `MISSING_TITLE` | Incomplete product records |
| Invalid/nonpositive price | `INVALID_PRICE`, `NONPOSITIVE_PRICE` | Unsafe product prices |
| Cost mistakes | `INVALID_COST`, `NEGATIVE_COST` | Bad supplier cost fields |
| Negative spread | `NEGATIVE_UNIT_SPREAD` | Unit cost greater than retail price |
| Low gross margin | `LOW_GROSS_MARGIN` | Margin lower than your threshold |
| Bad stock quantities | `INVALID_STOCK`, `NEGATIVE_STOCK` | Inventory data problems |
| Missing image | `MISSING_IMAGE` | No image field or empty image URL |
| Unexpected currency | `UNEXPECTED_CURRENCY` | Mismatched ISO currency value |
| Large price change | `LARGE_PRICE_CHANGE` | Price changed more than your threshold |
| Stock fall | `STOCK_DROP` | Inventory decrease beyond your threshold |
| SKU added/removed | `NEW_PRODUCT`, `REMOVED_PRODUCT` | Catalog changed since baseline |

### Quick start

Provide **exactly one current feed source**: a public HTTPS URL (`currentFeedUrl`) or pasted CSV/TSV/JSON (`currentFeedText`). Your feed must have at least a **SKU** and **price** column; a title, cost, stock, currency, and image column unlock additional checks. Common header synonyms are detected automatically.

Optional: provide an older version under `previousFeedUrl` or `previousFeedText` to enable change detection.

#### Example current feed

```csv
sku,title,price,cost,stock,currency,image_url
A-101,Adjustable laptop stand,39.99,17.00,20,USD,https://example.com/laptop.jpg
B-102,Desk cable clips,9.99,10.40,16,USD,
```

To check against a previous feed, paste a snapshot into `previousFeedText` or use the corresponding HTTPS URL. Set `minMarginPercent` to `20`, and `priceChangeAlertPercent` to `25`.

### Outputs

Open **Output → Issues** for a searchable JSON dataset. Under **Output → Reports**, download:

- **`REPORT.html`** — visual audit summary and actionable findings.
- **`FINDINGS.csv`** — one row per finding, ready for spreadsheet review.
- **`FINDINGS.json`** — machine-readable issues for integration.
- **`SUMMARY`** — stats and parsed column mapping.

You can schedule recurring runs using Apify schedules. Each run compares the inputs provided for that run; **MarginDiff does not automatically fetch yesterday's snapshot from a previous run**. Your upstream system must provide or host the baseline for change detection. This avoids storing customer catalogs indefinitely within the Actor itself.

### Pricing and limits

This Actor's creator chooses a price for one `audit-completed` event in Apify's **Pay per event** settings. **A charge is attempted only after successfully auditing the feed.** The default run accepts up to 10,000 products per feed; hard limit is 20,000. Text and public HTTPS downloads are capped at 8 MB each. No browser automation or paid proxy network is used.

**Important:** Publishing this source alone does **not** create monetization. The creator must enable the `audit-completed` event and set its price in Apify Console.

### Privacy & safety

- Supply only catalogs you own or are authorized to audit.
- The URL downloader accepts public HTTPS feed URLs with valid certificates, pins a validated public IP address, blocks private/internal address ranges, rejects credentials and redirects, and imposes a 12-second timeout.
- Do not include customer identities, private tokens, passwords, or other secrets. Apify retains run input and output under its storage and retention policies.
- Data is not sent to a third-party AI service. No external telemetry or external APIs are called other than the optional user-specified feed URL.
- CSV output guards against spreadsheet formula injection.

### Limitations

- A gross margin estimate **does not** include marketplace fees, shipping, returns, duty, tax, fulfillment, or overhead. It is not a full net-profit calculation.
- Monetary parsing expects dot decimal notation (`19.99`); comma decimals must be normalized upstream.
- The Actor checks field values but does not open image URLs or verify that every product is safe, sellable, or compliant with a marketplace.
- A public feed URL must resolve directly to a publicly accessible HTTPS resource; redirects, authentication, custom ports, and private networks are unsupported.
- When the previous feed contains duplicate SKUs, comparison uses the last occurrence of that SKU; remove duplicates before comparing.
- This is not a Google Merchant Center certification tool or a stock reconciliation with a live store.

### Support and maintenance

Most weeks should require checking only run failures or user reports. If feed formats change, update aliases or use column overrides. Release updates after automated tests pass. Prompt handling of customer-reported issues is the creator's responsibility.

See `PUBLISH_AND_PRICING.md` for publisher setup. The program's core calculations can be tested locally without an Apify account: `python -m unittest discover -s tests -v` and `python scripts/demo.py`.

# Actor input Schema

## `currentFeedUrl` (type: `string`):

Public, unauthenticated HTTPS URL to a CSV, TSV or JSON feed. Provide EITHER this URL OR pasted text. No redirects or private addresses.

## `currentFeedText` (type: `string`):

Paste CSV/TSV with headers or JSON array. Leave blank if using a URL.

## `previousFeedUrl` (type: `string`):

Optional public HTTPS URL to a previous snapshot for change detection.

## `previousFeedText` (type: `string`):

Optional baseline for added/removed SKUs, price changes and stock drops.

## `minMarginPercent` (type: `number`):

Flag products with (price - unit cost) / price below this percentage. This ignores shipping and fees.

## `priceChangeAlertPercent` (type: `number`):

Compared to the previous feed.

## `stockDropAlertPercent` (type: `number`):

Flag products when their reported stock drops by this percentage or more relative to the previous feed.

## `expectedCurrency` (type: `string`):

Example: USD. Leave blank to skip this check.

## `requireImage` (type: `boolean`):

If enabled, flag products with no image URL or an empty image field.

## `maxRows` (type: `integer`):

Hard maximum is 20,000 per feed. Raise only if your feeds require it.

## `skuColumn` (type: `string`):

Optional exact name of the SKU column when automatic header detection does not find it.

## `titleColumn` (type: `string`):

Optional exact name of the product title column when automatic header detection does not find it.

## `priceColumn` (type: `string`):

Optional exact name of the retail selling price column when automatic header detection does not find it.

## `costColumn` (type: `string`):

Optional exact name of the supplier unit cost column when automatic header detection does not find it.

## `stockColumn` (type: `string`):

Optional exact name of the stock quantity column when automatic header detection does not find it.

## `currencyColumn` (type: `string`):

Optional exact name of the currency column when automatic header detection does not find it.

## `imageColumn` (type: `string`):

Optional exact name of the image URL column when automatic header detection does not find it.

## Actor input object example

```json
{
  "minMarginPercent": 20,
  "priceChangeAlertPercent": 25,
  "stockDropAlertPercent": 50,
  "requireImage": true,
  "maxRows": 10000
}
```

# Actor output Schema

## `issues` (type: `string`):

No description

## `reports` (type: `string`):

No description

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("001hp/margindiff-supplier-feed-auditor").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("001hp/margindiff-supplier-feed-auditor").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 '{}' |
apify call 001hp/margindiff-supplier-feed-auditor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,001hp/margindiff-supplier-feed-auditor"
        }
    }
}
```

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/de46X8XdhUmouORrt/builds/LXBJBR6JLA7fRe7T6/openapi.json
