Skip to main content
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.
The parameter is typed any in the SDK; the platform requires currency. Returns — the basket as a BasketInstance with status active. Example
ErrorsFailed 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.
Returns — an array of BasketInstance. Example
ErrorsFailed 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.
Returns
Basket
The raw basket record, not an instance.
Example
ErrorsFailed to add item to basket.

removeItem()

Removes one item from a basket.
string
required
The basket’s id.
string
required
The item’s id.
Returns — the raw basket record, as addItem(). ErrorsFailed to remove item from basket.

clear()

Removes every item from a basket.
Returns — the raw basket record, as addItem(). ErrorsFailed to clear basket.

updateStatus()

Sets a basket’s status.
string
required
The basket’s id.
BasketStatus
required
The status to set.
Returns — typed as the status you set. Local runs resolve the status you passed; deployed agents resolve the updated basket record. Don’t branch on the resolved value; re-read with getById() when you need the basket. Example
ErrorsFailed to update basket status.

updateMetadata()

Writes basket metadata.
Returns — typed as the metadata. Local runs resolve the object you passed; deployed agents resolve the platform’s response envelope. Re-read with getById() when you need the stored metadata. Example
ErrorsFailed 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 basket checked_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.
Returns — the order as an OrderInstance with status pending. Example
ErrorsFailed to create order.

getById()

Returns one basket by id.
Returns — the basket as a BasketInstance. An unknown id throws; there is no null return. Example
ErrorsFailed to get basket.

BasketInstance

The object create(), 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.
The identity fields 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.
Returns — the basket’s fields, { ...data, ...common }.

removeItem()

Removes one item and refreshes the instance.

clear()

Removes every item and refreshes the instance.

updateStatus()

Sets the status and updates basket.status.

updateMetadata()

Writes metadata and merges it into the local metadata.

placeOrder()

Creates an order from the basket, then sets the basket’s status to checked_out.
Example

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