Skip to main content
Orders creates an order from a basket and reads or updates the current end user’s orders. An order carries the basket’s items and currency, your own data fields (shipping, payment, notes), and platform-maintained status, totalAmount, and itemCount. 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 order from a basket’s items.
string
required
The basket to convert.
Record<string, any>
required
Your order fields, for example shippingAddress, paymentMethod, and notes.
The parameter is typed any in the SDK; the platform requires basketId. Returns — the order as an OrderInstance with status pending. Example
ErrorsFailed to create order.

updateStatus()

Sets an order’s status. The status comes first.
OrderStatus
required
One of the OrderStatus values.
string
required
The order’s id.
Returns
OrderResponse
The raw order record, not an instance.
Example
ErrorsFailed to update order status.

updateData()

Merges fields into an order’s data. The data comes first.
Record<string, any>
required
Fields to add or replace.
string
required
The order’s id.
Returns — the raw order record, as updateStatus(). Example
ErrorsFailed to update order data.

get()

Returns the current end user’s orders, optionally filtered by status.
OrderStatus
Omit it for every order.
Returns — an array of OrderInstance. Example
ErrorsFailed to get user orders.

getById()

Returns one order by id.
Returns — the order as an OrderInstance. An unknown id throws; there is no null return. Example
ErrorsFailed to get order.

OrderInstance

The object create(), get(), getById(), and Baskets.placeOrder() return. Every order field is readable directly through the instance’s proxy: status, totalAmount, itemCount, and currency from the platform, items, basketId, orderDate, createdAt, and your own data fields. Direct assignments stay local until save(). The identity fields id, orderId, userId, and agentId and the raw data and common objects are private in the type declarations, so order.id doesn’t compile. Read the id from order.toJSON().id. totalAmount is typed string | number; wrap it in Number() before arithmetic.

updateStatus()

Sets the status and refreshes the instance’s platform fields.
Returns — the order’s fields, { ...data, ...common, id }.

update()

Merges fields into data on the server and refreshes the instance.
Returns — the order’s fields, { ...data, ...common, id }.

save()

Writes the whole local data to the server.
Returnstrue. Example
ErrorsFailed to save order data.

toJSON()

Returns { ...data, ...common, id }, which is what JSON.stringify(order) and console.log(order) print.

Types

OrderStatus

OrderInstance and OrderStatus are exported. OrderResponse is not; name it from Orders.updateStatus.

See also