Skip to main content
Item code shown on a stock item

Inventory > Stock Items > [Item] > General

Definition

A stock code (also called an item code) is a tenant-unique string that identifies a single Stock Item. A Stock Item carries a codes array — it can have one or many codes attached, which is how a single physical item supports multiple scanning workflows (an internal asset code, a printed barcode, a manufacturer serial number) at the same time.
The Analogy: A stock code is like a Social Security Number for an item — it follows the physical object through its entire lifecycle and is how every other record in TWICE refers back to it.
Multiple codes per item. TWICE’s codes field is an array. You can attach the manufacturer’s serial number, a printed asset tag, and an internal code to the same Stock Item and scan any of them to find it.

Stock Code vs SKU Code

These are different identifiers at different levels. A bike B-1 (stock code) is one specific unit of the BIK-S (SKU code) product. Twenty bikes of the same model = twenty stock codes pointing to one SKU code.

Where do I use it?

Stock codes are used throughout TWICE for:
  • Unique identification — referencing specific items in orders, reports, and operations.
  • Barcode and QR scanning — physical labels link directly to the digital record.
  • Bulk fulfillment workflows — scan items in and out at pickup and return.
  • Data integrity — the uniqueness constraint prevents duplicate records.
  • API operations — programmatically interact with specific Stock Items.
  • Audit trails — order history and event logs reference the codes used at the time.

Key Properties

System-generated vs custom codes

You have three ways to set codes:

Auto-generated

Omit codes when creating the article. TWICE generates an 8-character random ID (e.g. LF93HXB1). Good for quick onboarding when you do not care about specific values.

Manual entry

Provide codes on create or update. Use any string format that fits your operation — short asset tags (B-1), serial numbers (SN-2024-00123), or location-prefixed codes (HEL-BIK-001). Validate before save with POST /articles/validate-code or batch with POST /articles/validate-codes.

Bulk register with pattern

In the admin Register stock items dialog you can auto-generate a sequence (B-1, B-2, …, B-N) when creating multiple units at once. This is the most common workflow for receiving a new shipment of identical units.

Multiple codes per item

A single Stock Item can have multiple values in its codes array. This is intentional and supports real-world scanning workflows:
  • SKI-001 — internal asset tag printed on a sticker.
  • SN240501234 — manufacturer serial number printed on the ski.
  • 9783161484100 — barcode on the original packaging.
Scanning any of these resolves to the same Stock Item. All three are kept in sync, so removing or replacing one does not break the others.

Code format rules

  • Type: string. No length limit enforced beyond the auto-generated default of 8.
  • Characters: any printable characters. Most operators stick to alphanumerics, hyphens, and underscores so codes survive label printers and barcode scanners.
  • Uniqueness: per tenant. Validated on create and update.
  • Case sensitivity: codes are stored case-sensitively but most scanning workflows treat them as case-insensitive — pick one casing convention and stick to it.
  • Whitespace: trim leading and trailing whitespace before saving. Embedded spaces work but make scanning fragile.
Good patterns:

QR codes and barcode scanning

Stock codes are designed to be encoded onto physical labels. Common workflows:
  • Print on receive. When new inventory arrives, register Stock Items with auto-generated or manual codes, then print labels straight from the admin.
  • Scan on pickup. Operators scan an item’s code when assigning it to a rental order — TWICE validates the code, finds the item, and attaches it to the order line.
  • Scan on return. The same scan flow runs in reverse to mark items as returned and flip state from Out to In.
  • Scan for lookup. Quick search via the admin: scan a code and jump straight to the item detail.
Because codes is an array, an item that has both an internal asset tag and a manufacturer barcode can be scanned on either label. Operators do not need to know which one they are looking at.

Uniqueness scope

The uniqueness constraint is per tenant (your TWICE Commerce account). Two different tenants can both have a B-1 Stock Item. Within a tenant:
  • Each code in any article’s codes array must be unique across all Stock Items.
  • Validation happens server-side on create and update via the articleCodes table.
  • Use POST /articles/validate-code (single) or POST /articles/validate-codes (batch) before submitting to fail fast with a clear error.

Relationships

Lifecycle

1

Creation

Codes are assigned on Stock Item creation.
If you submit codes: ["..."] they are used as-is. If you omit codes, TWICE generates an 8-character random code. The Register stock items bulk dialog can also generate a sequence.
Yes. POST /articles/validate-code with { code } returns { isUnique }. POST /articles/validate-codes with { codes: [...] } returns the list of invalid codes and their reason (existing).
2

Usage

Codes are the everyday handle on a Stock Item.
On the Stock Item detail, in the table column, in orders that include the item, on labels you print, in scanning workflows, and in every API response that includes the Article.
Yes. The Stock Items table search and the global admin search resolve codes to their Stock Item. The API supports filters.code for exact and partial matching.
3

Modification

Codes can be added, removed, or replaced.
Edit the item and append to the codes array, or PUT /articles/:id with the new full array. The change is logged as an identifiers_changed event with the previous and new arrays.
Yes — replace the array with the new value. The old code is detached and immediately becomes available for use on another item.
Order line items and ledger entries reference the Stock Item by its id, not by its code. Changing or removing a code does not break historical links.

FAQs

Yes. Codes are not immutable — you can add, remove, or replace them at any time. The change is recorded in the activity log as identifiers_changed. Historical orders and ledger entries link by item id, not by code, so they remain valid.
They are the same thing. “Stock code” emphasises the inventory tracking angle; “item code” emphasises that it identifies a specific physical item. In the API, the field is codes on the Article resource.
No — codes are unique across all Stock Items in a tenant. If you try to create or update with a duplicate code, the operation fails with an existing validation reason.
Yes. The codes field is an array. You can attach an internal code, a manufacturer serial number, and a packaging barcode to the same Stock Item — scanning any of them resolves to that item.
Whatever fits your operation. Most operators use alphanumerics with hyphens or underscores so codes survive label printers and barcode scanners. The system generates 8-character random codes when you omit a value.
Per tenant. A code is unique across your whole account, not just within one service location. Two locations in the same TWICE tenant cannot both have B-1.

Developer Reference

Stock codes are managed via the articles endpoints. Use validate-code to check uniqueness before creating.

API: Articles

Open the endpoint in the API reference.

Stock Items

The records that codes identify

SKUs

SKU code vs item code

Inventory Tracking

Codes behave differently for serialized vs pooled inventory