Mobile stock counting endpoint (v3.164 / #753, engine shipped as #752): the counting half of the CMS Inventory > Stocktake tool. Shop and warehouse staff count shelves on handheld devices while the shop stays open and POS keeps selling — the reconciliation that makes this safe lives in the CMS (a per-session diary window anchored at a forced CR absorb), not in the app. The app's job is exactly one thing: feed counted lines to the session, never write stock.
tbl_stocktake_lines. The CMS applies the results:
shops get a restock transfer (warehouse → shop, quantities grossed back
to the session anchor so POS sales during the count never double-deduct);
the warehouse gets finalize (absolute set-to per shelf/batch).retiring are not countable yet (the retire batches
are still moving the old quantities out); count answers not_counting.Two layers, exactly like picking:
Authorization1 API key +
username + password + account, or the Inventory Manager token lane
(token + username + account).user_token — an ACTIVE mobile-app token of a CMS user of the
SAME account (log in via verify_user and reuse the token). The user
needs the order_picker or inventory permit; account administrators
(super_admin / reseller / administrator) always pass.action — the action name (required)session_id — the counting session (all write actions + info)user_token — the mobile-app user token (required){"status":"success","action":"count","data":{...}}
{"status":"error","action":"count","error_code":"not_counting","data":{...}}
HTTP 200 carries counting-flow outcomes (unknown_code, not_counting,
session_not_found, …); 4xx/5xx are auth/parameter failures.
Lists counting sessions (status counting or restocked; include_done=1
adds everything). Optional location_id filter.
{action:"sessions", location_id?:11} → response rows carry
session_id, location_id, location_name, kind (shop|warehouse), status, anchor_time, counted_lines.One session + the live summary (counted vs snapshot product counts, gap
count, movement totals since the anchor). Heavy gap lists are omitted here —
use summary.
{action:"lookup", session_id, code:"6401234567890"} (or
pid instead of code; free text with letters triggers a title search).products[] (max 10): pid, title, barcode, prdNumber, price,
expected[] = snapshot rows {shelf_id, best_before_date, old_stock, default_location} (default bin first, biggest stock first), counted[] =
existing lines {line_id, shelf_id, best_before_date, qty, counted_at}.unknown_code.Upserts one count line. An existing line with the same (session, pid, shelf, bbd) is replaced (qty + counted_at refreshed).
{action:"count", session_id, pid, qty, shelf_id?, bbd?}qty may be 0 (explicitly counted zero). shelf_id 0 = the product's
snapshot default shelf. bbd empty = whole-shelf semantics.not_counting, product_not_found, shelf_not_in_location.{action:"count_bulk", session_id, lines:[{pid, qty, shelf_id?, bbd?}, ...]} → {lines_ok, lines_failed, errors[]} per line.Removes one counted line ({action:"line_delete", session_id, line_id}) —
only while the session is counting.
Full session summary including the gap list (gaps[]: snapshot products
with no count line) and the last 200 count lines. The supervisor view.
| action | key params | writes | |
|---|---|---|---|
| sessions | location_id?, include_done? | — | |
| session_info | session_id | — | |
| lookup | session_id, code | pid | — |
| count | session_id, pid, qty, shelf_id?, bbd? | session line | |
| count_bulk | session_id, lines[] | session lines | |
| line_delete | session_id, line_id | session line | |
| summary | session_id | — |
curl -s -X POST https://shop.example.com/public_api/stocktake/ \
-H "Authorization1: <api key>" \
-d "account=1&username=api&password=***" \
-d "user_token=7f2d…" \
-d "action=lookup&session_id=3&code=6401234567890"
// Android/Kotlin — count 24 units on shelf 68, whole shelf (no bbd)
val body = FormBody.Builder()
.add("account", account).add("username", user).add("password", pass)
.add("user_token", token)
.add("action", "count").add("session_id", "3")
.add("pid", "1017").add("qty", "24").add("shelf_id", "68")
.build()
The counting flow, the CMS tool and the diary balance fix are documented in
blueprints/stocktake-blueprint.md (repo) — the app only needs this page.