# Stock Shortage Allocation Preview (`winning_moonstone/stock-shortage-allocation-preview`) Actor

Preview how limited stock would be distributed across order lines by priority or FIFO. See exact fills, backorders and missing stock scope without reserving inventory.

- **URL**: https://apify.com/winning_moonstone/stock-shortage-allocation-preview.md
- **Developed by:** [月 明](https://apify.com/winning_moonstone) (community)
- **Categories:** Business, Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$50.00 / 1,000 completed stock shortage allocation previews

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

## Stock Shortage Allocation Preview

See how a limited, caller-supplied stock snapshot would be distributed across order lines before anyone changes an ERP. Choose **priority then date** or **first in, first out**. The report lists the proposed fill and backorder for every line, remaining stock, and any demand whose SKU/unit has no matching stock row.

This is a review-only what-if calculator. It does not reserve inventory, promise delivery, contact customers or write to purchasing systems.

### Quick start

Run the included example. Ten units are available. The first order requests eight at priority 1; the second requests seven at priority 2. The preview assigns eight and two units, leaving a five-unit backorder. Export the dataset as JSON or CSV, or read `REPORT` from the default key-value store.

Input is one `caseJson` string containing an object with `caseId`, `policy`, `coverageConfirmed`, `stock`, and `demand`. `stock` rows contain `sku`, `unit`, and `available`. Demand rows contain `orderId`, `lineId`, `sku`, `unit`, `quantity`, `priority` (1–5), and `orderDate` (YYYY-MM-DD). Available and requested quantities are whole units. Use **unreserved** available stock, and set `coverageConfirmed` true only when the stock and demand scope is complete.

`PRIORITY_THEN_DATE` sorts by ascending priority then order date. `FIFO` sorts by date then priority. Order and line IDs break final ties, so input row order does not change the allocation. Lower priority numbers mean greater priority. Allocation is greedy within each exact SKU/unit. Partial fills are permitted. Missing stock rows are **unknown**, never silently interpreted as zero. If scope is incomplete, the overall result is `INCOMPLETE_REVIEW`, even though known rows have a preview.

### Pricing

**$0.05 per completed report**. A report with shortages or incomplete coverage is still a completed report. Malformed input and runs with insufficient event budget produce no report event. Set an Apify maximum-charge limit when testing. Platform resource usage can apply separately. Check the live Pricing tab before use.

### Limits and safety

At most 500 stock rows, 2,000 demand rows and 1 MB of UTF-8 JSON. Identifiers are exact, case-sensitive and limited to 100 characters. The Actor rejects duplicate stock keys, duplicate order/line keys, noninteger quantities, invalid dates and unexpected fields. It makes no external network requests and requires no AI or paid API. Avoid customer names, addresses, bank details and credentials; opaque IDs are enough.

The supplied stock snapshot is not independently verified. Separate runs do not share reservation state; rerun with updated stock before any business decision. The result is **never** an order approval or reservation. Unit conversion, substitutions, future replenishment, shipping time and customer commitments are outside scope.

### Why this tool

Microsoft documents reserving scarce inventory by first ordered or customer priority, and SAP documents FIFO and proportional stock allocation. This Actor offers a compact, auditable preview for teams working from structured exports, without requiring ERP access. Demand evidence does not prove that users will pay for this Actor.

References: [Microsoft inventory reservations](https://learn.microsoft.com/en-us/dynamics365/supply-chain/inventory/reserve-inventory-quantities), [SAP allocation](https://help.sap.com/docs/SAP_ERP/f48e74ad3b3740bc8c9eaade394a3c1e/f6a6f15562e37b43e10000000a4450e5.html).

# Actor input Schema

## `caseJson` (type: `string`):

Supply current unreserved stock and demand lines. Quantities are whole units. PRIORITY_THEN_DATE uses 1 as highest priority; FIFO uses order date first. This preview never writes reservations.

## Actor input object example

```json
{
  "caseJson": "{\n  \"caseId\": \"shortage-demo-001\",\n  \"policy\": \"PRIORITY_THEN_DATE\",\n  \"coverageConfirmed\": true,\n  \"stock\": [{\"sku\": \"PART-A\", \"unit\": \"EA\", \"available\": 10}],\n  \"demand\": [\n    {\"orderId\": \"ORDER-101\", \"lineId\": \"1\", \"sku\": \"PART-A\", \"unit\": \"EA\", \"quantity\": 8, \"priority\": 1, \"orderDate\": \"2026-10-01\"},\n    {\"orderId\": \"ORDER-102\", \"lineId\": \"1\", \"sku\": \"PART-A\", \"unit\": \"EA\", \"quantity\": 7, \"priority\": 2, \"orderDate\": \"2026-10-02\"}\n  ]\n}\n"
}
```

# Actor output Schema

## `dataset` (type: `string`):

No description

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

No description

## `summary` (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("winning_moonstone/stock-shortage-allocation-preview").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("winning_moonstone/stock-shortage-allocation-preview").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 winning_moonstone/stock-shortage-allocation-preview --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,winning_moonstone/stock-shortage-allocation-preview"
        }
    }
}
```

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/QIPbmJwPgxlwSeHJ4/builds/3zdeBtIeolDCupprx/openapi.json
