Nano Store - Ecommerce Docs
Developer Resourcesb2b-second-inventory

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

SurfaceBase PathAuth
Stock/api/admin/bb/inventoryJWT + BB_Inventory_*
Stock jobs/api/admin/bb/jobs/inventoryJWT + 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

MethodPathAuthDescription
GET/api/admin/bb/inventoryBB_Inventory_READPaginated stock rows of live variants of live products
GET/api/admin/bb/inventory/products/:productPublicIdBB_Inventory_READEvery live variant's row for one live product, by (position, id). Not paginated
GET/api/admin/bb/inventory/products/:productPublicId/variants/:variantPublicIdBB_Inventory_READOne live variant's row
GET/api/admin/bb/inventory/products/:productPublicId/movementsBB_Inventory_READA live product's ledger, newest first. Includes deleted variants' history
GET/api/admin/bb/inventory/products/:productPublicId/variants/:variantPublicId/movementsBB_Inventory_READOne live variant's ledger, newest first
PATCH/api/admin/bb/inventory/products/:productPublicId/variants/:variantPublicId/configurationBB_Inventory_UPDATESet the low-stock threshold, guarded by version
POST/api/admin/bb/inventory/products/:productPublicId/variants/:variantPublicId/adjustBB_Inventory_UPDATEAdd or remove units. Needs Idempotency-Key. Returns 200
POST/api/admin/bb/inventory/bulk/adjustBB_Inventory_UPDATEAdjust 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

MethodPathAuthDescription
POST/api/admin/bb/jobs/inventory/importBB_Catalog_CREATE + BB_Inventory_CREATE + BB_Inventory_UPDATESubmit a stock import. Multipart field file (.csv or .xlsx), header Idempotency-Key (required). Returns 201 { publicId }
POST/api/admin/bb/jobs/inventory/exportBB_Catalog_READ + BB_Inventory_READSubmit a stock export. Body { search?, stockStatus? }. Needs Idempotency-Key. Returns 201 { publicId }
POST/api/admin/bb/jobs/inventory/:publicId/cancelBB_Catalog_UPDATE + BB_Inventory_UPDATECancel a queued or processing job. Returns 200 with the job
GET/api/admin/bb/jobs/inventoryBB_Catalog_READ + BB_Inventory_READPaginated job list, newest first. Query: page, size (max 100)
GET/api/admin/bb/jobs/inventory/import-templateBB_Catalog_READ + BB_Inventory_READCSV with the header row only
GET/api/admin/bb/jobs/inventory/:publicId/resultBB_Catalog_READ + BB_Inventory_READDownload a completed export CSV
GET/api/admin/bb/jobs/inventory/:publicIdBB_Catalog_READ + BB_Inventory_READOne 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):

ParamRule
pageInteger from 1. Default 1
sizeInteger 1 to 100. Default 20
searchTrimmed, at most 100 characters. Matches the product name or the variant SKU
stockStatusout_of_stock, low_stock or in_stock
driftedtrue: only rows the reconciler flagged. false or omitted: no drift filter. Any other value is a 400
sortupdatedAt (default), quantity or productName. Ties break on variant id
orderasc 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"
}
FieldRule
deltaWhole number, not 0, from -1,000,000 to 1,000,000
reasonrestock, recount, damage, theft or correction. import is a 400
noteOptional. 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,note

Answers 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,lastMovementAt

A 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:

CodeStatusWhen
BB_INVENTORY_NOT_FOUND404A live variant has no stock row. Logged as an ERROR; the hourly reconcile creates the row
BB_INVENTORY_INSUFFICIENT_STOCK409The change would take quantity below 0. details.variantPublicId names the row
BB_INVENTORY_QUANTITY_LIMIT400The change would take quantity above 1,000,000,000
BB_INVENTORY_REASON_SIGN_MISMATCH400restock with a negative delta, or damage or theft with a positive one
BB_INVENTORY_VERSION_CONFLICT409The threshold's version is stale
BB_INVENTORY_BULK_DUPLICATE_VARIANT400Two bulk items name one variant
BB_VARIANT_HAS_STOCK409DELETE .../products/:productPublicId/variants/:publicId on a variant with quantity above 0
BB_JOB_INVENTORY_FILE_ALREADY_IMPORTED409A 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

GuardrailValue
Items per bulk adjust100
Largest single change1,000,000 either way
Largest quantity1,000,000,000
Note length1,000 characters
Stock list size100
Movements limit100
Import rows / export rows5,000 / 50,000
Active jobs per admin2

See Also