# Amazon Landed Cost Margin Audit (`practical_ai_lab_jp/pal-amazon-landed-cost-margin-audit`) Actor

Offline audit of two seller offer and cost exports: finds margin erosion by seller and SKU, rejects mixed currencies and missing freight.

- **URL**: https://apify.com/practical_ai_lab_jp/pal-amazon-landed-cost-margin-audit.md
- **Developed by:** [Practical AI Lab](https://apify.com/practical_ai_lab_jp) (community)
- **Categories:** E-commerce, Developer tools
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $20.00 / 1,000 offer pair auditeds

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

## Amazon Landed Cost Margin Audit

Compare two exports of your own (or a client-authorized) ASIN seller offers and cost/fee data, and get a reproducible list of offers whose profit margin got worse, rolled up by seller and SKU.

This Actor **does not scrape Amazon or any other site and makes no network requests**. It only analyzes the data you paste in.

### What it does

1. Validates every row of a **baseline** and a **current** export.
2. **Rejects** rows with missing freight cost, mixed currencies (never converts), invalid ASINs, ambiguous fees, or duplicate ASIN + seller + SKU keys.
3. Matches offers on ASIN + seller + SKU and computes landed-cost margin for each side:
   `margin = price - unit_cost - freight - duty - other - referral_fee - fba_fee` (per unit).
4. Reports an **exception** when margin percentage falls by at least your threshold (default 3 points) or an offer flips from profit to loss, with the largest cost driver, per-unit and per-volume impact, both row snapshots, and a SHA-256 evidence hash.
5. Adds per-seller rollups and a `SUMMARY` record with an input fingerprint so the same input always gives the same result.

### Input columns

Required: `asin`, `seller`, `sku`, `currency`, `price`, `unit_cost`, `freight_cost`, and exactly one of `referral_fee_pct` (e.g. `15`) or `referral_fee` (amount).
Optional: `duty_cost`, `other_cost`, `fba_fee` (default 0), `units` (default 1, used to weight volume impact).
Blank freight means "unknown" and is rejected; enter `0` if there truly is none.

### Sample input

```json
{
  "baselineCsv": "asin,seller,sku,currency,price,unit_cost,freight_cost,referral_fee_pct,fba_fee,units\nB000000001,Northwind Goods,NW-100,USD,29.99,9.50,1.20,15,5.10,120",
  "currentCsv": "asin,seller,sku,currency,price,unit_cost,freight_cost,referral_fee_pct,fba_fee,units\nB000000001,Northwind Goods,NW-100,USD,27.99,9.50,2.90,15,5.40,130",
  "expectedCurrency": "USD",
  "marginDropPoints": 3
}
```

You can also pass `baselineRecords` / `currentRecords` as JSON arrays of row objects. Common header spellings (for example `Seller SKU`, `COGS`, `Offer Price`) are recognized.

### Output

- Dataset records with `recordType` of `exception`, `seller_rollup`, or `rejected` (separate views in the Console).
- Key-value store `SUMMARY`: counts, rejection reasons, unmatched offers, fingerprint, caveats.

### Pricing event

The code emits the event `offer-pair-audited` (one per matched offer, capped by `maxPairs`) only after results are stored. Failed runs are not charged. No payable plan is configured in this repository.

### Limitations

- Garbage in, garbage out: results are only as accurate as your cost and fee columns. Fees are not looked up or estimated.
- Currencies are never converted; use one currency per audit.
- Seller-level averages from fewer than 30 matched offers are anecdotal; the summary says so.
- Offers present in only one export are counted but not compared.
- Input is capped (default 20,000 rows per export) to keep memory low.
- You are responsible for having the right to use the data you supply.

# Actor input Schema

## `baselineCsv` (type: `string`):

Earlier period offer and cost export, with a header row.

## `currentCsv` (type: `string`):

Latest period offer and cost export, same columns as the baseline.

## `baselineRecords` (type: `array`):

Alternative or addition to the baseline CSV: an array of row objects using the same column names.

## `currentRecords` (type: `array`):

Alternative or addition to the current CSV: an array of row objects using the same column names.

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

Three-letter code such as USD. Rows in any other currency are rejected, never converted. If empty, the most common currency in the data is used.

## `marginDropPoints` (type: `integer`):

Report an offer when its margin percentage falls by at least this many points. Offers that turn from profitable to loss-making are always reported.

## `maxPairs` (type: `integer`):

Upper bound on matched ASIN + seller + SKU offers audited (and billed).

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

Input larger than this fails the run without charge.

## Actor input object example

```json
{
  "baselineCsv": "asin,seller,sku,currency,price,unit_cost,freight_cost,duty_cost,referral_fee_pct,fba_fee,units\nB000000001,Northwind Goods,NW-100,USD,29.99,9.50,1.20,0.60,15,5.10,120\nB000000001,Contoso Supply,CS-100,USD,28.99,9.80,1.10,0.60,15,5.10,60\nB000000002,Northwind Goods,NW-200,USD,19.99,6.00,0.90,0.30,15,3.80,200\nB000000003,Contoso Supply,CS-300,USD,49.00,20.00,2.50,1.00,15,7.00,40",
  "currentCsv": "asin,seller,sku,currency,price,unit_cost,freight_cost,duty_cost,referral_fee_pct,fba_fee,units\nB000000001,Northwind Goods,NW-100,USD,27.99,9.50,2.90,0.60,15,5.40,130\nB000000001,Contoso Supply,CS-100,USD,28.99,9.80,1.10,0.60,15,5.10,55\nB000000002,Northwind Goods,NW-200,USD,19.99,6.00,,0.30,15,3.80,210\nB000000003,Contoso Supply,CS-300,EUR,45.00,20.00,2.50,1.00,15,7.00,35",
  "marginDropPoints": 3,
  "maxPairs": 5000,
  "maxRows": 20000
}
```

# Actor output Schema

## `results` (type: `string`):

Download rows from the latest run in JSON/CSV.

# 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 = {
    "baselineCsv": `asin,seller,sku,currency,price,unit_cost,freight_cost,duty_cost,referral_fee_pct,fba_fee,units
B000000001,Northwind Goods,NW-100,USD,29.99,9.50,1.20,0.60,15,5.10,120
B000000001,Contoso Supply,CS-100,USD,28.99,9.80,1.10,0.60,15,5.10,60
B000000002,Northwind Goods,NW-200,USD,19.99,6.00,0.90,0.30,15,3.80,200
B000000003,Contoso Supply,CS-300,USD,49.00,20.00,2.50,1.00,15,7.00,40`,
    "currentCsv": `asin,seller,sku,currency,price,unit_cost,freight_cost,duty_cost,referral_fee_pct,fba_fee,units
B000000001,Northwind Goods,NW-100,USD,27.99,9.50,2.90,0.60,15,5.40,130
B000000001,Contoso Supply,CS-100,USD,28.99,9.80,1.10,0.60,15,5.10,55
B000000002,Northwind Goods,NW-200,USD,19.99,6.00,,0.30,15,3.80,210
B000000003,Contoso Supply,CS-300,EUR,45.00,20.00,2.50,1.00,15,7.00,35`
};

// Run the Actor and wait for it to finish
const run = await client.actor("practical_ai_lab_jp/pal-amazon-landed-cost-margin-audit").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 = {
    "baselineCsv": """asin,seller,sku,currency,price,unit_cost,freight_cost,duty_cost,referral_fee_pct,fba_fee,units
B000000001,Northwind Goods,NW-100,USD,29.99,9.50,1.20,0.60,15,5.10,120
B000000001,Contoso Supply,CS-100,USD,28.99,9.80,1.10,0.60,15,5.10,60
B000000002,Northwind Goods,NW-200,USD,19.99,6.00,0.90,0.30,15,3.80,200
B000000003,Contoso Supply,CS-300,USD,49.00,20.00,2.50,1.00,15,7.00,40""",
    "currentCsv": """asin,seller,sku,currency,price,unit_cost,freight_cost,duty_cost,referral_fee_pct,fba_fee,units
B000000001,Northwind Goods,NW-100,USD,27.99,9.50,2.90,0.60,15,5.40,130
B000000001,Contoso Supply,CS-100,USD,28.99,9.80,1.10,0.60,15,5.10,55
B000000002,Northwind Goods,NW-200,USD,19.99,6.00,,0.30,15,3.80,210
B000000003,Contoso Supply,CS-300,EUR,45.00,20.00,2.50,1.00,15,7.00,35""",
}

# Run the Actor and wait for it to finish
run = client.actor("practical_ai_lab_jp/pal-amazon-landed-cost-margin-audit").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 '{
  "baselineCsv": "asin,seller,sku,currency,price,unit_cost,freight_cost,duty_cost,referral_fee_pct,fba_fee,units\\nB000000001,Northwind Goods,NW-100,USD,29.99,9.50,1.20,0.60,15,5.10,120\\nB000000001,Contoso Supply,CS-100,USD,28.99,9.80,1.10,0.60,15,5.10,60\\nB000000002,Northwind Goods,NW-200,USD,19.99,6.00,0.90,0.30,15,3.80,200\\nB000000003,Contoso Supply,CS-300,USD,49.00,20.00,2.50,1.00,15,7.00,40",
  "currentCsv": "asin,seller,sku,currency,price,unit_cost,freight_cost,duty_cost,referral_fee_pct,fba_fee,units\\nB000000001,Northwind Goods,NW-100,USD,27.99,9.50,2.90,0.60,15,5.40,130\\nB000000001,Contoso Supply,CS-100,USD,28.99,9.80,1.10,0.60,15,5.10,55\\nB000000002,Northwind Goods,NW-200,USD,19.99,6.00,,0.30,15,3.80,210\\nB000000003,Contoso Supply,CS-300,EUR,45.00,20.00,2.50,1.00,15,7.00,35"
}' |
apify call practical_ai_lab_jp/pal-amazon-landed-cost-margin-audit --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,practical_ai_lab_jp/pal-amazon-landed-cost-margin-audit"
        }
    }
}
```

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/qV4bZGg2FbVD7g1Kf/builds/uqG1inIvczxO03UNE/openapi.json
