B2B Second Inventory Stock API Reference
Endpoint reference for the bb phase 3 admin stock API — stock list and detail, movements, adjust, bulk adjust, low-stock threshold, and stock import/export jobs — with contracts, permissions and error codes.
B2B Second Inventory (bb) — Stock API Reference
Audience: Admin engineers integrating with the bb phase 3 backend. Phase 3 has no storefront or public endpoint.
All endpoints are prefixed with /api, need a JWT, and need the listed permission. Superadmin passes every permission check. Every response uses the ResponseDto envelope (message, errorCode, data; a paginated list adds count, currentPage, totalPage; a cursor list adds nextCursor).
Throttles per IP: reads ADMIN_READ (30 per 60 s), single writes ADMIN_WRITE (10 per 60 s), bulk adjust ADMIN_BULK_WRITE (5 per 60 s).
The request and response examples below are shaped from the DTO classes. They were not captured from a running server.
Route Surfaces
| Surface | Base Path | Auth |
|---|---|---|
| Stock | /api/admin/bb/inventory | JWT + BB_Inventory_* |
| Stock jobs | /api/admin/bb/jobs/inventory | JWT + BB_Catalog_* plus BB_Inventory_* |
Every :productPublicId, :variantPublicId and :publicId is a UUID (a malformed one is a 400). There is no route that addresses a product's "default variant": every write names the variant.
Endpoint Reference
Stock
| Method | Path | Auth | Description |
|---|---|---|---|
| GET | /api/admin/bb/inventory | BB_Inventory_READ | Paginated stock rows of live variants of live products |
| GET | /api/admin/bb/inventory/products/:productPublicId | BB_Inventory_READ | Every live variant's row for one live product, by (position, id). Not paginated |
| GET | /api/admin/bb/inventory/products/:productPublicId/variants/:variantPublicId | BB_Inventory_READ | One live variant's row |
| GET | /api/admin/bb/inventory/products/:productPublicId/movements | BB_Inventory_READ | A live product's ledger, newest first. Includes deleted variants' history |
| GET | /api/admin/bb/inventory/products/:productPublicId/variants/:variantPublicId/movements | BB_Inventory_READ | One live variant's ledger, newest first |
| PATCH | /api/admin/bb/inventory/products/:productPublicId/variants/:variantPublicId/configuration | BB_Inventory_UPDATE | Set the low-stock threshold, guarded by version |
| POST | /api/admin/bb/inventory/products/:productPublicId/variants/:variantPublicId/adjust | BB_Inventory_UPDATE | Add or remove units. Needs Idempotency-Key. Returns 200 |
| POST | /api/admin/bb/inventory/bulk/adjust | BB_Inventory_UPDATE | Adjust up to 100 variants. Needs Idempotency-Key. Returns 200 |
A deleted or missing product answers 404 BB_PRODUCT_NOT_FOUND; a deleted or missing variant answers 404 BB_VARIANT_NOT_FOUND. Stock routes never return a deleted variant's row.
Stock jobs
| Method | Path | Auth | Description |
|---|---|---|---|
| POST | /api/admin/bb/jobs/inventory/import | BB_Catalog_CREATE + BB_Inventory_CREATE + BB_Inventory_UPDATE | Submit a stock import. Multipart field file (.csv or .xlsx), header Idempotency-Key (required). Returns 201 { publicId } |
| POST | /api/admin/bb/jobs/inventory/export | BB_Catalog_READ + BB_Inventory_READ | Submit a stock export. Body { search?, stockStatus? }. Needs Idempotency-Key. Returns 201 { publicId } |
| POST | /api/admin/bb/jobs/inventory/:publicId/cancel | BB_Catalog_UPDATE + BB_Inventory_UPDATE | Cancel a queued or processing job. Returns 200 with the job |
| GET | /api/admin/bb/jobs/inventory | BB_Catalog_READ + BB_Inventory_READ | Paginated job list, newest first. Query: page, size (max 100) |
| GET | /api/admin/bb/jobs/inventory/import-template | BB_Catalog_READ + BB_Inventory_READ | CSV with the header row only |
| GET | /api/admin/bb/jobs/inventory/:publicId/result | BB_Catalog_READ + BB_Inventory_READ | Download a completed export CSV |
| GET | /api/admin/bb/jobs/inventory/:publicId | BB_Catalog_READ + BB_Inventory_READ | One job, with errors |
A caller needs every listed code. The routes share the catalog job machinery: states, errors[], limits and the download rules are in the catalog API page. Job lists and reads are scoped to the entity in the path.
Key Contracts
GET /api/admin/bb/inventory
Query (all optional):
| Param | Rule |
|---|---|
page | Integer from 1. Default 1 |
size | Integer 1 to 100. Default 20 |
search | Trimmed, at most 100 characters. Matches the product name or the variant SKU |
stockStatus | out_of_stock, low_stock or in_stock |
drifted | true: only rows the reconciler flagged. false or omitted: no drift filter. Any other value is a 400 |
sort | updatedAt (default), quantity or productName. Ties break on variant id |
order | asc or desc (default) |
There is no pagination=false: the list is always paginated, and any undeclared query key is a 400.
Response data[] (also the body of the single-row, product, adjust and configuration responses):
{
"productPublicId": "0192f6d0-0000-7000-8000-000000000001",
"productName": "Test Tee",
"productIsActive": true,
"variantPublicId": "0192f6d0-0000-7000-8000-000000000002",
"variantName": "Pack",
"variantDisplayName": "Pack",
"variantSku": "TEE-PACK",
"variantIsActive": true,
"isDefaultVariant": false,
"quantity": 10,
"lowStockThreshold": 5,
"stockStatus": "in_stock",
"version": 1,
"lastMovementAt": "2026-11-03T08:46:00.000Z",
"driftDetectedAt": null,
"updatedAt": "2026-11-03T08:46:00.000Z",
"createdAt": "2026-11-03T08:40:00.000Z"
}variantDisplayName is the label, else the option values, else the product name. variantPublicId is the row identity. There is no price, no integer id and no lastReconciledAt. version guards the threshold only.
GET .../movements
Query: limit (default 20, maximum 100) and before_seq (return rows with id below this; pass the previous page's nextCursor). after_seq and cursor are not accepted (400). A bad limit or before_seq answers 422 PAGINATION_LIMIT_INVALID, PAGINATION_LIMIT_TOO_LARGE or PAGINATION_CURSOR_INVALID.
{
"message": "Bb inventory movements fetched successfully",
"errorCode": null,
"data": [
{
"publicId": "0192f6d1-0000-7000-8000-000000000003",
"variantPublicId": "0192f6d0-0000-7000-8000-000000000002",
"variantDisplayName": "Pack",
"variantSku": "TEE-PACK",
"reason": "restock",
"quantityDelta": 10,
"quantityAfter": 10,
"note": null,
"actorName": "QA Superadmin",
"correlationId": null,
"createdAt": "2026-11-03T08:46:00.000Z"
}
],
"nextCursor": null
}reason is restock, recount, damage, theft, correction or import. actorName is a snapshot taken at write time. correlationId is the job public id for an import and null otherwise.
POST .../variants/:variantPublicId/adjust
Header Idempotency-Key (required).
{
"delta": -3,
"reason": "damage",
"note": "Water damage in the back store"
}| Field | Rule |
|---|---|
delta | Whole number, not 0, from -1,000,000 to 1,000,000 |
reason | restock, recount, damage, theft or correction. import is a 400 |
note | Optional. Trimmed; blank is dropped; at most 1,000 characters; no NUL |
Answers 200 with the updated row (same shape as above) and writes one ledger row and one bb.inventory.adjust audit row. restock needs a positive delta; damage and theft need a negative one. Returns 400 BB_INVENTORY_REASON_SIGN_MISMATCH otherwise.
POST /api/admin/bb/inventory/bulk/adjust
Header Idempotency-Key (required).
{
"reason": "recount",
"note": "Shelf count 2026-11-03",
"items": [
{ "variantPublicId": "0192f6d0-0000-7000-8000-000000000002", "delta": -2 },
{ "variantPublicId": "0192f6d0-0000-7000-8000-000000000004", "delta": 4 }
]
}One reason and note for the whole request. items: 1 to 100, each with a UUID variantPublicId and a delta under the single adjust's rule. Two items for one variant answer 400 BB_INVENTORY_BULK_DUPLICATE_VARIANT and nothing is written.
Items commit independently. A refusal does not fail the request:
{
"message": "Bulk adjust processed.",
"errorCode": null,
"data": {
"succeeded": ["0192f6d0-0000-7000-8000-000000000004"],
"failed": [
{
"publicId": "0192f6d0-0000-7000-8000-000000000002",
"errorCode": "BB_INVENTORY_INSUFFICIENT_STOCK",
"message": "That would take stock below zero."
}
]
}
}succeeded and failed[].publicId hold variant public ids. A variant that is missing or deleted fails with BB_VARIANT_NOT_FOUND.
PATCH .../variants/:variantPublicId/configuration
{ "lowStockThreshold": 6, "version": 1 }lowStockThreshold is an integer from 0 to 1,000,000,000 (0 means never warn). version is an integer of at least 1, the value the caller loaded. A stale version answers 409 BB_INVENTORY_VERSION_CONFLICT, even if the threshold matches. An unchanged threshold writes nothing and returns the row as is.
POST /api/admin/bb/jobs/inventory/import
Multipart field file, a .csv or .xlsx whose header row is exactly:
variantPublicId,quantityDelta,noteAnswers 201 { "publicId": "<job uuid>" }. The job runs on the bb_catalog queue. If any row fails, the job ends failed, errors[] lists each row with its column and reason, and no row is written. Row reasons: delta_format, note_too_long, variant_not_live, duplicate_variant, insufficient_stock, quantity_limit, plus the catalog's file-level ones.
A second upload of byte-identical content answers 409 BB_JOB_INVENTORY_FILE_ALREADY_IMPORTED while the first job is queued, processing or completed. Change a note and upload again to apply it on purpose.
POST /api/admin/bb/jobs/inventory/export
{ "search": "tee", "stockStatus": "low_stock" }Both fields are optional. includeDeleted is not accepted (400). The result CSV columns are:
variantPublicId,productPublicId,productName,variantName,sku,quantity,lowStockThreshold,stockStatus,lastMovementAtA match count above 50,000 answers 400 BB_JOB_EXPORT_TOO_LARGE at submit.
Error body
Errors use the standard envelope with errorCode set. Branch on errorCode, not on the message or the status.
Error Reference
New in phase 3:
| Code | Status | When |
|---|---|---|
BB_INVENTORY_NOT_FOUND | 404 | A live variant has no stock row. Logged as an ERROR; the hourly reconcile creates the row |
BB_INVENTORY_INSUFFICIENT_STOCK | 409 | The change would take quantity below 0. details.variantPublicId names the row |
BB_INVENTORY_QUANTITY_LIMIT | 400 | The change would take quantity above 1,000,000,000 |
BB_INVENTORY_REASON_SIGN_MISMATCH | 400 | restock with a negative delta, or damage or theft with a positive one |
BB_INVENTORY_VERSION_CONFLICT | 409 | The threshold's version is stale |
BB_INVENTORY_BULK_DUPLICATE_VARIANT | 400 | Two bulk items name one variant |
BB_VARIANT_HAS_STOCK | 409 | DELETE .../products/:productPublicId/variants/:publicId on a variant with quantity above 0 |
BB_JOB_INVENTORY_FILE_ALREADY_IMPORTED | 409 | A stock import of byte-identical content while an earlier one is queued, processing or completed |
Reused from the catalog on these routes: BB_PRODUCT_NOT_FOUND and BB_VARIANT_NOT_FOUND (404), BB_CATALOG_BUSY (409, a lock timeout or deadlock; nothing was written), VALIDATION_FAILED (400), IDEMPOTENCY_KEY_REQUIRED (400), IDEMPOTENCY_KEY_CONFLICT and IDEMPOTENCY_REQUEST_IN_PROGRESS (409), and the job codes BB_JOB_FILE_INVALID, BB_JOB_FILE_TOO_LARGE, BB_JOB_TOO_MANY_ACTIVE, BB_JOB_IDEMPOTENCY_CONFLICT, BB_JOB_NOT_FOUND, BB_JOB_NOT_CANCELLABLE, BB_JOB_RESULT_NOT_AVAILABLE, BB_JOB_RESULT_GONE.
Guardrail Summary
| Guardrail | Value |
|---|---|
| Items per bulk adjust | 100 |
| Largest single change | 1,000,000 either way |
Largest quantity | 1,000,000,000 |
| Note length | 1,000 characters |
Stock list size | 100 |
Movements limit | 100 |
| Import rows / export rows | 5,000 / 50,000 |
| Active jobs per admin | 2 |
See Also
B2B Second Inventory Stock Backend Documentation
Internal architecture of the bb phase 3 stock — composition, data model, the single stock writer, lock order, import and export handlers, the hourly reconcile, error contract and file map.
B2B Second Inventory Stock Deploy Notes
Deploy order, the variant row count check, the required permissions:sync and role grant, intermediate states, verification and the rollback runbook for bb phase 3 migrations 0063 and 0064.