# Let an AI agent warn you before a Wildberries size sells out

> Source: <https://dev.to/timmyzinin/let-an-ai-agent-warn-you-before-a-wildberries-size-sells-out-1kd9>
> Published: 2026-11-28 09:10:58+00:00

**Key takeaway:** The Wildberries Scraper returns a per-size quantity and available flag for each nmId, so agents should check size-level stock rather than the product-level available flag, which stays true until the last size sells out.

On Wildberries, a listing can look fully in stock and still have one pair left in the size your customer wears. Take one pair of platform sneakers, product 152540730, with more than 150,000 ratings. On 20 November size 45 had 1 unit and size 43 had 42. On 28 November it was the other way round: size 43 had 1 unit and size 45 had 50. Size 46 showed 0 both times. Over the same eight days the price went from 1,340 to 1,245 RUB.

A shopping agent that recommends this product in size 43 today is about to send someone to an empty shelf. A reseller who only checks the listing page misses the moment a competitor's size runs out. Both need stock per size. The product's own "in stock" flag stays true until the last size is gone.

I built [Wildberries Scraper](https://apify.com/zinin/wildberries-scraper?fpr=u5ov8x&utm_source=devto&utm_medium=social&utm_campaign=apify-actors&utm_content=wildberries-size-stock-watch-agent) on Apify for this. Give it Wildberries article numbers (`nmId`, the number in the product URL) and it returns one row per product: current price in RUB, the pre-discount price, discount, rating and rating count, seller and seller rating, and a `sizes` array with a `quantity` and an `available` flag for every size. It also searches by keyword, but keyword rows have no size stock. No Wildberries account is needed.

The input is a list of article numbers:

```
{"productIds": ["152540730", "1152945426"]}
```

The second ID is a knitted dress, picked because its sizes are ranges such as 46-50.

Here is part of the sneaker row from the run on 28 November (run `2tRlMAag3dcgsY7tj`, build 0.8.1, finished in 13 seconds), copied from the dataset with some fields and sizes cut:

```
{
  "id": 152540730,
  "brand": "JOYCITY",
  "price": {"value": 1245, "currency": "RUB", "originalValue": 3659},
  "discount": 66,
  "rating": {"value": 4.8, "count": 152748},
  "supplier": "JOYCITY",
  "supplierRating": 4.8,
  "available": true,
  "sizes": [
    {"name": "42", "originalName": "42", "optionId": 285949177, "quantity": 50, "available": true},
    {"name": "43", "originalName": "43", "optionId": 285949178, "quantity": 1, "available": true},
    {"name": "44", "originalName": "44", "optionId": 285949179, "quantity": 45, "available": true},
    {"name": "46", "originalName": "46", "optionId": 375171979, "quantity": 0, "available": false}
  ],
  "url": "https://www.wildberries.ru/catalog/152540730/detail.aspx"
}
```

The dress came back with three sizes: `46-50` with 3 units, `52-54` with 10 and `56-58` with 7, at 4,712 RUB.

The product-level `available` is `true` because some sizes are in stock. That flag alone would have hidden the size 43 problem.

This is the same sneaker across two runs, eight days apart:

One caution on the numbers. On 20 November ten sizes showed exactly 42 units; on 28 November nine showed exactly 50. I would not read 50 as fifty pairs on a shelf. The Actor adds up the per-warehouse quantities that Wildberries returns for each size. For well-stocked sizes the result looks like a ceiling: in the 20 November run, the phone and the thermos I tested alongside also showed exactly 42. The low end is what I act on: 0 means the size is gone, 1 or 2 means it is about to be.

This Python script runs the Actor, compares every size with the previous run and prints only sizes that have just dropped to 2 units or fewer. It needs `pip install apify-client` (tested with version 3.5.1) and your Apify token in `APIFY_TOKEN`.

``` python
import json
import os
from decimal import Decimal
from pathlib import Path

from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])
SNAPSHOT = Path("wb_sizes.json")
LOW = 2  # alert when a size has this many units or fewer

run = client.actor("zinin/wildberries-scraper").call(
    run_input={"productIds": ["152540730", "1152945426"]},
    max_total_charge_usd=Decimal("0.05"),
)
rows = client.dataset(run.default_dataset_id).list_items().items

before = json.loads(SNAPSHOT.read_text()) if SNAPSHOT.exists() else {}
now, alerts = {}, []
for row in rows:
    if row.get("error") or not row.get("sizes"):
        continue  # free explanation rows and fallback rows carry no stock
    for size in row["sizes"]:
        key = f'{row["id"]}:{size["name"] or "one-size"}'
        qty = size["quantity"]
        now[key] = qty
        was = before.get(key)
        if qty is not None and qty <= LOW and (was is None or was > LOW):
            alerts.append(f'{row["name"][:40]} size {size["name"] or "-"}: {was} -> {qty}, '
                          f'price {row["price"]["value"]} RUB')

SNAPSHOT.write_text(json.dumps(now))
print("\n".join(alerts) or "no new low-stock sizes")
```

The first time I ran it, with no earlier snapshot, it printed two lines (the product name is Russian, cut to 40 characters):

``` php
Кроссовки спортивные на платформе демисе size 43: None -> 1, price 1245 RUB
Кроссовки спортивные на платформе демисе size 46: None -> 0, price 1245 RUB
```

The dress stayed quiet, because none of its sizes was at 2 or fewer. Run the script on a schedule and it reports each size only when it crosses the line.

For an agent, the same Actor can be added as a tool through Apify's MCP server. The instruction I would give it: "Before you recommend a Wildberries product in a specific size, run the Actor with its article number and check that size's `quantity`. If it is 0, say so. If it is 1 or 2, warn that it may be gone soon. If it is null, say the stock is unknown right now."

Here is the public Actor page:

As of November 2026, there is no start fee and each product row delivered to the dataset costs $0.00299, so the two-product run above cost $0.00598 in Actor events, and 1,000 products cost $2.99 (the Actor description rounds this to $3 per 1,000). Rows that only explain an error are free. Set "Max total charge" on the run (or `max_total_charge_usd` in code, as above) and the Actor stops before it goes over, with a free row saying where it stopped.

`productIds`. Keyword search rows have price, rating, seller and position, but no `sizes`. To watch a category, search first, then pass the IDs you care about.`name` is an empty string. The script above stores that size under the key "one-size".`price` and `quantity` are `null`. Treat `error` and the rest of the run continues.
Try [Wildberries Scraper](https://apify.com/zinin/wildberries-scraper?fpr=u5ov8x&utm_source=devto&utm_medium=social&utm_campaign=apify-actors&utm_content=wildberries-size-stock-watch-agent) on a listing you sell against and see which of its sizes are already down to one.

*Disclosure: I maintain this Actor. Drafted with AI assistance using the cited successful runs. This article contains Apify affiliate links; I may earn a commission if you sign up for a paid plan through them.*
