Baskets creates and manages the current end user’s shopping baskets and converts one into an order. A basket holds items (each with a product id, price, and quantity), a currency, free-form metadata, and platform-maintained itemCount, totalAmount, and status. Available wherever a current end user exists: tools, dynamic jobs, and trigger-fired turns (see execution contexts).
Verified against lua-cli 3.33.0.
Quick example
Methods
create()
Creates an empty basket for the current end user.string
required
Currency code, for example
USD.Record<string, any>
Free-form data stored with the basket.
any in the SDK; the platform requires currency.
Returns — the basket as a BasketInstance with status active.
Example
Failed to create basket.
get()
Returns the current end user’s baskets, optionally filtered by status.BasketStatus
One of the
BasketStatus values. Omit it for every basket.BasketInstance.
Example
Failed to get user baskets.
addItem()
Adds an item to a basket.string
required
The basket’s id.
{ id: string; price: number; quantity: number; SKU?: string; [key: string]: any }
required
The product
id, unit price, and quantity, plus any fields of your own such as SKU, color, or size.Basket
The raw basket record, not an instance.
Failed to add item to basket.
removeItem()
Removes one item from a basket.string
required
The basket’s id.
string
required
The item’s
id.addItem().
Errors — Failed to remove item from basket.
clear()
Removes every item from a basket.addItem().
Errors — Failed to clear basket.
updateStatus()
Sets a basket’s status.string
required
The basket’s id.
BasketStatus
required
The status to set.
getById() when you need the basket.
Example
Failed to update basket status.
updateMetadata()
Writes basket metadata.getById() when you need the stored metadata.
Example
Failed to update basket metadata.
placeOrder()
Creates an order from a basket’s items. This static form leaves the basket’s status unchanged; the instance form also marks the basketchecked_out.
Record<string, any>
required
Your order fields, for example
shippingAddress and paymentMethod. Stored on the order’s data.string
required
The basket to convert.
OrderInstance with status pending.
Example
Failed to create order.
getById()
Returns one basket by id.BasketInstance. An unknown id throws; there is no null return.
Example
Failed to get basket.
BasketInstance
The objectcreate(), get(), and getById() return. Its methods refresh the instance from the platform’s response, so itemCount, totalAmount, and status are current after each call.
BasketStatus
active, checked_out, abandoned, or expired.number
Total quantity across items.
string | number
Basket total. Wrap it in
Number() before arithmetic.any
The basket’s metadata.
any
Readable directly through the instance’s proxy.
id, userId, and agentId and the raw data and common objects are private in the type declarations, so basket.id doesn’t compile. Read the id from basket.toJSON().id.
addItem()
Adds an item and refreshes the instance.{ ...data, ...common }.
removeItem()
Removes one item and refreshes the instance.clear()
Removes every item and refreshes the instance.updateStatus()
Sets the status and updatesbasket.status.
updateMetadata()
Writes metadata and merges it into the localmetadata.
placeOrder()
Creates an order from the basket, then sets the basket’s status tochecked_out.
toJSON()
Returns{ ...data, ...common, id }: items, currency, metadata, createdAt, status, totalAmount, itemCount, and id.
Types
BasketStatus
BasketInstance and BasketStatus are exported. Basket and BasketItem are not; name them from Baskets.addItem.
See also
Products— the catalog items come fromOrders— whatplaceOrder()createsJobs— schedule an abandoned-basket follow-up- Commerce REST API — baskets over HTTP

