# Warehouse Cycle Count Variance API (`afkdigital/newapi88-warehouse-cycle-count-variance`) Actor

Review warehouse cycle count discrepancies with exact quantities, explicit recount selection and evidence. CSV, XLSX and JSON.

- **URL**: https://apify.com/afkdigital/newapi88-warehouse-cycle-count-variance.md
- **Developed by:** [AFK Digital](https://apify.com/afkdigital) (community)
- **Categories:** E-commerce, Business
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 unique count line revieweds

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

## Warehouse Cycle Count Variance API

Compare physical cycle counts with a matching warehouse inventory snapshot. Review shortages, overages and recount candidates without connecting to a WMS/ERP or changing source inventory. Inputs and outputs support CSV, XLSX and JSON.

### Quick start

Run the prefilled synthetic demo. It contains a shortage, an overage, a missing cost and a missing count. It uses no external website, proxy, AI model or customer credentials. A normal demo should complete well under five minutes.

### Input files

Required: `countFile`, `inventorySnapshotFile`, `unitCostsFile`, `snapshotTime` (ISO 8601 with explicit UTC offset). Additional inputs: `columnMapping`, `optionalStockMovementsFile`, `quantityTolerance`, `valueTolerance`, `maxCountLines` and optional `unitConversions`.

Each file is an object. Use `{"rows":[...]}` for JSON rows, `{"format":"csv","content":"sku,qty\n001,2\n"}` for CSV text, `{"format":"xlsx","base64":"..."}` for XLSX, or `{"format":"csv","keyValueStoreId":"YOUR_PRIVATE_STORE","key":"COUNTS.csv"}` for a private Apify record. Select the referenced store in the read-only `sourceKeyValueStores` picker (API: an array of store IDs) so the run receives narrowly scoped READ access. Inline rows/content/base64 need no storage permission. JSON and XLSX also work with KVS references. Arbitrary HTTP URLs and filesystem paths are not accepted. XLSX must contain one worksheet with literal values, no formulas/macros/external links. Use text cells for SKU, lot and serial identifiers to preserve leading zeros and long numeric IDs.

| File / mapping group | Columns |
| --- | --- |
| countFile / count | warehouse, location, sku, lot_or_serial (optional), count_id, counted_at, qty or counted_qty, unit, is_valid (optional) |
| inventorySnapshotFile / inventory | warehouse, location, sku, lot_or_serial (optional), qty or system_qty, unit, snapshot_at (optional) |
| unitCostsFile / costs | sku, unit_cost, currency, unit; optional warehouse/location/lot_or_serial scopes |
| optionalStockMovementsFile / movements | warehouse, location, sku, lot_or_serial (optional), movement_id, occurred_at, qty or quantity_delta (signed), unit |

Map canonical names to your headers: `{"count":{"sku":"Item Code","qty":"Physical Qty"},"inventory":{"sku":"Item Code"}}`. A group mapping must include every column needed from that file. With no mapping the canonical names are used. Identifiers are trimmed, case-sensitive, and blank lot/serial values match only other blanks. One row is one complete count of its exact stock key; split-bin partial counts are not automatically summed.

### Reconciliation rules

- Match warehouse + location + SKU + lot/serial. Do not collapse lots, locations or currencies. Missing inventory is flagged, never assumed zero.
- Exact duplicate rows are ignored while their evidence row numbers are retained. Distinct duplicate inventory or cost rows are ambiguous, not summed or arbitrarily selected.
- Counts marked `is_valid:false` are excluded. Select the newest valid `counted_at` at each key. Earlier counts are evidence only. Same-time distinct records are `ambiguous_count`. Missing quantity, count ID, valid timestamp or nonnegative finite quantity yields review rather than silently selecting an older count. A blank/missing count is never physical zero. Use explicit `qty:"0"` for a real zero count.
- At the same timestamp: `quantity_variance = counted_qty - system_qty`. For different times, provide **complete movement coverage**: a movement descriptor with `complete:true`, `coverageStart`, `coverageEnd`, plus rows or file content. The interval must cover both timestamps, including an explicit empty rows array if there were no movements. Apply signed movements in `(earlier, later]`; reverse the adjustment when the count precedes the snapshot. Missing/incomplete coverage or invalid movement data produces `time_mismatch` and null variance. Completeness is the customer's assertion; the API cannot verify omitted movements.
- Units must be explicit and equal, or have exactly one customer-provided SKU conversion `{sku,fromUnit,toUnit,factor}`. Factors are positive decimal strings and directional. Never infer a case size or measurement conversion. Quantities and costs use decimal arithmetic with up to 12 decimal places and absolute input values up to 1e18. Output decimals are strings to preserve precision.
- A unique applicable unit cost produces `value_variance = quantity_variance * unit_cost` in its own currency. Missing/ambiguous/invalid cost leaves value null but keeps a valid quantity variance. ISO-style uppercase three-letter currency codes are required; no currency conversion or combined currency totals.
- A row requires recount when absolute quantity difference exceeds `quantityTolerance` OR absolute value difference exceeds `valueTolerance`. Boundary values are within tolerance. Value tolerance applies independently in the row currency; missing values are not treated as zero.

### Results

Default Dataset: JSON/CSV exports through Apify. Additional private run KVS records: `REPORT`, `REPORT.csv`, `RECOUNT_QUEUE`, `RECOUNT_QUEUE.csv`, `SUMMARY`. The recount queue includes every row requiring attention, including missing data; it does not update a WMS or send messages.

Main fields: count_id, warehouse, location, sku, lot_or_serial, system_qty, counted_qty, quantity_variance, unit_cost, value_variance, currency, review_status, evidence_rows. Evidence identifies 1-based data rows (header excluded), with the selected count distinguished from previous counts. Additional fields describe quantity unit, timing and issues; SUMMARY records billing status.

### Limits and data handling

10 MiB per file, 40 MiB total input JSON, 100,000 rows per input file, 100 columns, 50 MiB expanded XLSX and 500 ZIP entries. `maxCountLines` is 1..100,000 (default 10,000), counted before duplicate removal. Files exceeding limits fail; no silent truncation. Output CSV protects textual formula prefixes. Customer rows are not logged and no third-party data enrichment is used. Customer files, Dataset and KVS outputs stay in the customer's Apify account under its access controls and retention settings. Avoid including unneeded personal data; delete inputs/outputs through Apify when no longer required. Any sharing of a public run or Dataset can expose uploaded data.

### Pricing

USD **1.00 per 1,000 successfully reviewed unique selected count rows**, implemented as one `count-line-reviewed` event at USD 0.001 per row. A final partial thousand is proportional, not rounded up. Quantity-only reviews with missing cost count as reviewed; unresolved keys, counts, time or units do not. No startup fee or default Dataset-item event should be enabled. Platform execution costs are intended to be included; post-run storage access follows Apify's platform terms.

An atomic named request queue reserves a hash before charging, scoped to the Actor and the running user. Identical selected count + stock key + timestamp + reconciled quantities/unit/snapshot is not charged again on reupload, even when tolerances or costs change. Earlier recounts and duplicate input rows do not generate additional events. Only opaque hashes are retained in the billing queue, not customer rows. Concurrent reservations deduplicate atomically. To avoid double billing after a crash, an interrupted reservation may waive one fee. Deleting this billing queue resets cross-run deduplication; retain it while you require repeat-upload protection. All results are persisted before billing. If the billing budget stops charging, the complete computed report remains available and SUMMARY flags budget_stopped; unfinished billing may waive fees. Pricing uses only the count-line-reviewed event. Startup and automatic Dataset-item fees are disabled. See the Store Pricing tab for the current rate.

### Development

Python 3.12. Install requirements, then `python -m unittest discover -s tests -v`. Run `python -m src.main` with an Apify INPUT record. Version 0.1.0. This API produces reconciliation candidates based on customer-provided data; it does not certify stock ownership, valuation or movement completeness.

# Actor input Schema

## `countFile` (type: `object`):

Use {rows:\[...]}, {format,content}, {format,base64}, or {format,keyValueStoreId,key}. Movements additionally require complete:true, coverageStart and coverageEnd.

## `inventorySnapshotFile` (type: `object`):

Use {rows:\[...]}, {format,content}, {format,base64}, or {format,keyValueStoreId,key}. Movements additionally require complete:true, coverageStart and coverageEnd.

## `unitCostsFile` (type: `object`):

Use {rows:\[...]}, {format,content}, {format,base64}, or {format,keyValueStoreId,key}. Movements additionally require complete:true, coverageStart and coverageEnd.

## `optionalStockMovementsFile` (type: `object`):

Use {rows:\[...]}, {format,content}, {format,base64}, or {format,keyValueStoreId,key}. Movements additionally require complete:true, coverageStart and coverageEnd.

## `columnMapping` (type: `object`):

Map canonical fields to source column names by group: count, inventory, costs, movements.

## `snapshotTime` (type: `string`):

ISO 8601 inventory snapshot timestamp including timezone.

## `quantityTolerance` (type: `string`):

Nonnegative decimal string. Value tolerance applies independently in each row currency.

## `valueTolerance` (type: `string`):

Nonnegative decimal string. Value tolerance applies independently in each row currency.

## `maxCountLines` (type: `integer`):

Fail rather than truncate if count input exceeds this number of raw rows.

## `unitConversions` (type: `array`):

Objects: sku, fromUnit, toUnit, factor (positive decimal string). No inferred conversion.

## `sourceKeyValueStores` (type: `array`):

Select every private key-value store referenced by a file descriptor. Grants only READ access to those selected stores. Leave empty for inline rows/content/base64.

## Actor input object example

```json
{
  "countFile": {
    "rows": [
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-001",
        "qty": "8",
        "unit": "EA",
        "count_id": "CNT-001",
        "counted_at": "2026-11-11T10:00:00Z"
      },
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-002",
        "qty": "12",
        "unit": "EA",
        "count_id": "CNT-002",
        "counted_at": "2026-11-11T10:00:00Z"
      },
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-003",
        "qty": "4",
        "unit": "EA",
        "count_id": "CNT-003",
        "counted_at": "2026-11-11T10:00:00Z"
      }
    ]
  },
  "inventorySnapshotFile": {
    "rows": [
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-001",
        "qty": "10",
        "unit": "EA"
      },
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-002",
        "qty": "10",
        "unit": "EA"
      },
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-003",
        "qty": "5",
        "unit": "EA"
      },
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-004",
        "qty": "7",
        "unit": "EA"
      }
    ]
  },
  "unitCostsFile": {
    "rows": [
      {
        "sku": "SKU-001",
        "unit": "EA",
        "unit_cost": "2.50",
        "currency": "USD"
      },
      {
        "sku": "SKU-002",
        "unit": "EA",
        "unit_cost": "3.00",
        "currency": "EUR"
      }
    ]
  },
  "columnMapping": {},
  "snapshotTime": "2026-11-11T10:00:00Z",
  "quantityTolerance": "0",
  "valueTolerance": "0",
  "maxCountLines": 10000,
  "unitConversions": []
}
```

# Actor output Schema

## `report` (type: `string`):

No description

## `csv` (type: `string`):

No description

## `recountQueue` (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 = {
    "countFile": {
        "rows": [
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-001",
                "qty": "8",
                "unit": "EA",
                "count_id": "CNT-001",
                "counted_at": "2026-11-11T10:00:00Z"
            },
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-002",
                "qty": "12",
                "unit": "EA",
                "count_id": "CNT-002",
                "counted_at": "2026-11-11T10:00:00Z"
            },
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-003",
                "qty": "4",
                "unit": "EA",
                "count_id": "CNT-003",
                "counted_at": "2026-11-11T10:00:00Z"
            }
        ]
    },
    "inventorySnapshotFile": {
        "rows": [
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-001",
                "qty": "10",
                "unit": "EA"
            },
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-002",
                "qty": "10",
                "unit": "EA"
            },
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-003",
                "qty": "5",
                "unit": "EA"
            },
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-004",
                "qty": "7",
                "unit": "EA"
            }
        ]
    },
    "unitCostsFile": {
        "rows": [
            {
                "sku": "SKU-001",
                "unit": "EA",
                "unit_cost": "2.50",
                "currency": "USD"
            },
            {
                "sku": "SKU-002",
                "unit": "EA",
                "unit_cost": "3.00",
                "currency": "EUR"
            }
        ]
    },
    "snapshotTime": "2026-11-11T10:00:00Z"
};

// Run the Actor and wait for it to finish
const run = await client.actor("afkdigital/newapi88-warehouse-cycle-count-variance").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 = {
    "countFile": { "rows": [
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-001",
                "qty": "8",
                "unit": "EA",
                "count_id": "CNT-001",
                "counted_at": "2026-11-11T10:00:00Z",
            },
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-002",
                "qty": "12",
                "unit": "EA",
                "count_id": "CNT-002",
                "counted_at": "2026-11-11T10:00:00Z",
            },
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-003",
                "qty": "4",
                "unit": "EA",
                "count_id": "CNT-003",
                "counted_at": "2026-11-11T10:00:00Z",
            },
        ] },
    "inventorySnapshotFile": { "rows": [
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-001",
                "qty": "10",
                "unit": "EA",
            },
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-002",
                "qty": "10",
                "unit": "EA",
            },
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-003",
                "qty": "5",
                "unit": "EA",
            },
            {
                "warehouse": "DEMO-WH",
                "location": "A-01",
                "sku": "SKU-004",
                "qty": "7",
                "unit": "EA",
            },
        ] },
    "unitCostsFile": { "rows": [
            {
                "sku": "SKU-001",
                "unit": "EA",
                "unit_cost": "2.50",
                "currency": "USD",
            },
            {
                "sku": "SKU-002",
                "unit": "EA",
                "unit_cost": "3.00",
                "currency": "EUR",
            },
        ] },
    "snapshotTime": "2026-11-11T10:00:00Z",
}

# Run the Actor and wait for it to finish
run = client.actor("afkdigital/newapi88-warehouse-cycle-count-variance").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 '{
  "countFile": {
    "rows": [
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-001",
        "qty": "8",
        "unit": "EA",
        "count_id": "CNT-001",
        "counted_at": "2026-11-11T10:00:00Z"
      },
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-002",
        "qty": "12",
        "unit": "EA",
        "count_id": "CNT-002",
        "counted_at": "2026-11-11T10:00:00Z"
      },
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-003",
        "qty": "4",
        "unit": "EA",
        "count_id": "CNT-003",
        "counted_at": "2026-11-11T10:00:00Z"
      }
    ]
  },
  "inventorySnapshotFile": {
    "rows": [
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-001",
        "qty": "10",
        "unit": "EA"
      },
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-002",
        "qty": "10",
        "unit": "EA"
      },
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-003",
        "qty": "5",
        "unit": "EA"
      },
      {
        "warehouse": "DEMO-WH",
        "location": "A-01",
        "sku": "SKU-004",
        "qty": "7",
        "unit": "EA"
      }
    ]
  },
  "unitCostsFile": {
    "rows": [
      {
        "sku": "SKU-001",
        "unit": "EA",
        "unit_cost": "2.50",
        "currency": "USD"
      },
      {
        "sku": "SKU-002",
        "unit": "EA",
        "unit_cost": "3.00",
        "currency": "EUR"
      }
    ]
  },
  "snapshotTime": "2026-11-11T10:00:00Z"
}' |
apify call afkdigital/newapi88-warehouse-cycle-count-variance --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,afkdigital/newapi88-warehouse-cycle-count-variance"
        }
    }
}
```

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/XHCTQSc09ncGL6orG/builds/hzgzXREfVXr7cedUv/openapi.json
