Skip to content

Advanced Inventory API

Pro Feature

All advanced inventory endpoints require FluentCart Pro to be installed and activated.

Manage stock across product variants: read current levels, adjust them individually or in bulk, read the audit trail of every adjustment, and export the whole inventory as CSV.

Base URL: https://your-site.com/wp-json/fluent-cart/v2

All routes in this group are guarded by ProductPolicy and require products/view to read or products/edit to write.


The four stock numbers

Every variant carries four related quantities. Getting these straight is the key to using this API correctly:

FieldMeaning
total_stockPhysical units on hand. This is what you set.
committedUnits sold and awaiting fulfillment.
on_holdUnits reserved by in-flight checkouts.
availableDerived: total_stock - committed - on_hold, floored at 0.

available is never written directly — it is recalculated on every adjustment. Because it is the derived value, it is also what the stats buckets are computed from, not total_stock.

Only variants with manage_stock = 1 appear anywhere in this API.


Adjustment reasons

Every write records an entry in the stock-adjustment audit trail, and every write must state a reason:

reasonLabel
receivedReceived Stock
damageDamage/Loss
returnReturn/Refund
correctionCount Correction
transferInventory Transfer
otherOther

When reason is other, customReason becomes required and is stored alongside the entry. Any other value for reason is rejected with 400.


Endpoints

List Inventory

GET /fluent-cart/v2/inventory

Paginated list of stock-managed products with their variants. A product appears only if its detail row and at least one of its variants have manage_stock = 1.

  • Permission: products/view
ParameterTypeLocationRequiredDescription
pageintegerqueryNoPage number.
per_pageintegerqueryNoRecords per page.
searchstringqueryNoMatches product title, variant SKU, or variation title. Also supports operator syntax (e.g. sku = TES-RED-XS).
sort_bystringqueryNoColumn to sort by (default: id).
sort_typestringqueryNoasc or desc.
active_viewstringqueryNoTab filter: all, low_stock, out_of_stock.
filter_typestringqueryNosimple (default) or advanced.
advanced_filtersstring (JSON)queryNoJSON-encoded advanced filter groups.
withstringqueryNoEager-load relations. See below.

The with parameter is allowlisted — arbitrary relation names are rejected rather than passed through:

ValueEffect
admin_inventory_listBoth relations, with variant columns narrowed. Used by the admin table.
detailThe catalogue detail row on its own.
variantsThe variant rows on their own, unnarrowed.

Extend it with the fluent_cart/inventory_allowed_withs filter.


Get Inventory Stats

GET /fluent-cart/v2/inventory/stats

Counts of stock-managed variants bucketed by availability.

  • Permission: products/view
json
{
  "totalVariants": 24,
  "inStock": 0,
  "lowStock": 24,
  "outOfStock": 0
}

Buckets are computed on available:

  • outOfStockavailable <= 0
  • lowStock0 < available <= threshold
  • inStockavailable > threshold

The threshold defaults to 10 and is filterable:

php
add_filter('fluent_cart/inventory_low_stock_threshold', function ($threshold) {
    return 25;
});

Get Adjustment History

GET /fluent-cart/v2/inventory/adjustment-history

Audit trail for one variant, newest first, capped at the 100 most recent entries.

  • Permission: products/view
ParameterTypeLocationRequiredDescription
variant_idintegerqueryYesReturns 400 Variant ID is required without it.

Each entry carries old_stock, new_stock, a computed change delta, the reason and its human-readable reason_label, and the acting user_name — which falls back to System when the user no longer exists.


Update Stock

POST /fluent-cart/v2/inventory/update-stock

Sets the absolute stock level for one variant and records an audit entry.

  • Permission: products/edit
FieldTypeRequiredDescription
variant_idintegerYesVariant to update.
post_idintegerYesParent product ID. Must match the variant's own post_id or the request returns 404.
new_stockintegerYesNew total_stock. Negative values are clamped to 0.
reasonstringYesSee reasons above.
customReasonstringConditionalRequired when reason is other.

Bulk Update Stock

POST /fluent-cart/v2/inventory/bulk-update

Adjusts many variants in one call.

  • Permission: products/edit
FieldTypeRequiredDescription
modestringYesset writes value as the new absolute stock; add adds value to the current stock.
valueintegerYesThe absolute value or the delta. Negative deltas subtract.
reasonstringYesSee reasons above.
customReasonstringConditionalRequired when reason is other.
itemsarrayYesArray of { "id": <variant_id> }. Only id is read.

Unknown IDs are skipped silently

Variant IDs that do not resolve are ignored without an error. The response's count is the number of variants actually updated — compare it against the number of items you sent to detect a partial application. An empty items array is a successful no-op with count: 0.


Export Inventory

POST /fluent-cart/v2/inventory/export

Builds a CSV and returns it inline as a string. No file is written and no download URL is issued — the client is expected to turn csvData into a file itself.

  • Permission: products/view
FieldTypeRequiredDescription
scopestringYesall, current_page (caps the query at 1000 rows), or selected (restricted to items).
inventoryStatestringYesavailable or full. Controls the column set.
formatstringNocsv_spreadsheet (default) prefixes a UTF-8 BOM so Excel opens the file correctly. Any other value omits it.
itemsarrayConditionalArray of { "id": <variant_id> }, read only when scope is selected.

Columns by inventoryState:

  • availableID, SKU, Product Title, Variation Title, Available
  • fullID, SKU, Product Title, Variation Title, Total Stock, Available, On Hold, Delivered

Note that the full header labels committed as Delivered.

FluentCart developer documentation