Skip to main content
Data stores JSON entries in named collections that belong to the agent and retrieves them by id, by a Lua Query filter, or by semantic search over an entry’s searchText. Available in tools, jobs, webhooks, triggers, processors, and workflow code steps. For one record per end user, use User instead. Verified against lua-cli 3.33.0.

Quick example

Methods

collections()

Lists the agent’s collections with entry counts, timestamps, and the status of any declared indexes.
Returns
CustomDataCollectionInfo[]
One entry per collection.
number
Number of collections.
Example
ErrorsFailed to list custom data collections.
Local runs only. The deployed runtime doesn’t expose collections() yet and fails with Data.collections is not a function. Inspect index status from lua test.

create()

Creates an entry and, when searchText is given, indexes it for search().
string
required
Collection name, for example movies.
Record<string, any>
required
Any JSON-serializable object.
string | { searchText?: string; index?: Array<string | string[]> }
A string sets searchText, the text search() embeds; include every term you expect queries to use. An object also accepts index: the data fields this agent filters on, each a single path ('businessId') or a compound of two paths (['country', 'businessId']). Declare indexes on every write; the platform builds them asynchronously and removes an index 14 days after its last declaration or matching filtered read. A compound index serves filters on its leftmost field alone or on both fields. Over-limit or invalid declarations are rejected and reported in collections(), never trimmed.
Returns
DataEntryInstance
The stored entry. Fields of data are readable directly (entry.title) and through entry.data.
Example
ErrorsFailed to create custom data entry when the platform rejects the write.
Local runs only. The deployed runtime doesn’t accept the options object yet and fails with searchText must be a string. In deployed code, pass searchText as a plain string.

get()

Returns one page of entries that match a filter.
string
required
Collection to read.
LuaQuery
Matches fields of each entry’s data. Grammar, operators, and limits are on the Lua Query page. Omit it to page through everything.
number
default:1
Page number, starting at 1.
number
default:10
Entries per page. The maximum is 100.
Returns
CustomDataEntry[]
Plain entries, not DataEntryInstance objects: read fields through entry.data.
Pagination
currentPage, totalPages, totalCount, limit, hasNextPage, hasPrevPage, nextPage (number or null), and prevPage (number or null).
Example
Errors — an invalid filter is rejected with a FILTER_* code (see Lua Query errors). A filter on an undeclared field of a large collection fails with an error that names the field and the index declaration to add.

getEntry()

Returns one entry by id.
string
required
Collection to read.
string
required
The entry’s id.
Returns — the entry as a DataEntryInstance. Example
ErrorsFailed to get custom data entry when no entry has that id.

update()

Merges fields into an entry and optionally replaces its searchText.
string
required
Collection that holds the entry.
string
required
The entry’s id.
Record<string, any>
required
Fields to add or replace. Other fields are kept.
string | { searchText?: string; index?: Array<string | string[]> }
As on create(): a string replaces searchText; an object may also refresh index declarations.
Returns
string
success on a completed write.
string
Human-readable result.
Example
ErrorsFailed to update custom data entry when no entry has that id or the platform rejects the write.
Local runs only. The deployed runtime doesn’t accept the options object yet and fails with searchText must be a string. In deployed code, pass searchText as a plain string.
Returns the entries whose searchText is semantically closest to a query.
string
required
Collection to search.
string
required
Natural-language query.
number
default:10
Maximum number of results. The maximum is 20.
number
default:0.6
Minimum similarity from 0 to 1. Results with a lower score are dropped.
Returns — a flat array of DataEntryInstance, each with a score from 0 to 1, best match first. Not the { data, pagination } envelope that get() returns. Example
Errors — none beyond network errors.

delete()

Deletes one entry.
string
required
Collection that holds the entry.
string
required
The entry’s id.
Returns
string
success on a completed delete.
string
Human-readable result.
Example
ErrorsFailed to delete custom data entry when no entry has that id.

DataEntryInstance

The object create(), getEntry(), and search() return. Fields of data are readable and writable directly (entry.subject) and through entry.data; direct assignments stay local until save().
string
Entry id.
string
The entry’s collection.
Record<string, any>
The stored object.
number
Similarity from 0 to 1. Set on search() results only.

update()

Merges fields into the entry on the server and locally.
Returns — the merged data. ErrorsFailed to update custom data entry, with the platform’s error as cause.

patch()

Sets and removes top-level fields, and optionally replaces or clears searchText, in one request.
Record<string, any>
Fields to set. A null value is stored as null.
string[]
Top-level fields to remove.
string | null
A replacement searchText, or null to clear it.
Returns — the data after the mutation. ErrorsFailed to patch custom data entry, with the platform’s error as cause.

unset()

Removes top-level fields; shorthand for patch({ unset: fields }).

delete()

Deletes the entry.
Returnstrue. ErrorsFailed to delete custom data entry, with the platform’s error as cause.

save()

Writes the whole local data to the server, optionally with a replacement searchText.
Returnstrue. Example
ErrorsFailed to save data entry, with the platform’s error as cause.

toJSON()

Returns { ...data, score, id, collectionName }, which is what JSON.stringify(entry) and console.log(entry) print.

Limits

Types

DataEntryInstance and LuaQuery are exported. The result shapes (CustomDataEntry, GetCustomDataResponse, CreateCustomDataOptions, CustomDataCollectionsResponse, UpdateCustomDataResponse, DeleteCustomDataResponse) are not; name them from the method that returns them.

See also