Timill Platform Documentation

JavaScript API

The objects and functions available to JavaScript backend scripts and scripted charts.

JavaScript runs in backend scripts and scripted charts. This page lists everything a script can use. For which of these each kind of script gets, see the overview; for the Jinja-style templates used by scripted widgets, see the Gonja reference.

The language#

Scripts run in an embedded JavaScript engine (goja) on the server. Modern syntax works — let/const, arrow functions, template literals, destructuring, spread, for…of, classes, Map and Set.

There is no browser, no Node.js and no event loop: require, import, eval, new Function, setTimeout, setInterval and promise-based I/O do not exist. fetch is synchronous and returns the response directly — never await it.

Conventions#

The whole API follows three rules.

Data is properties, actions are methods. Write item.title, user.name, group.id — no parentheses. Anything that takes an argument or does work is a method: group.queryItems(q), item.getField(id), item.setTitle(t).

Properties are read-only. Assigning item.title = "x" changes nothing (and throws in strict mode). Use the setters.

Writes return a result, reads throw. Every write method returns {success: true} or {success: false, error: "…"} and never throws, so check success when it matters. A read that cannot work — a malformed query, a file that is not on the item — throws an error with the reason.

const r = item.setField("priority", "high");
if (!r.success) log("could not set priority:", r.error);

The script’s last expression is its result. Objects and arrays are recorded as JSON. For a scripted chart, that result is the chart; see Scripted charts.

user#

The user the script runs as.

PropertyType
idstring
namestringdisplay name
emailstring
profilePicturestringavatar URL, "" when none
localestringthe user’s language, "" when not chosen
isActivebooleanfalse for a deleted account

Backend scripts only:

MethodReturns
updateProfile({name, language})resultupdates the given keys; empty values are ignored
save()resultkept for compatibility; writes nothing (updateProfile saves immediately)

group#

The group the script belongs to.

PropertyType
idstring
namestring
MethodReturns
queryItems(query)Item[]items matching a query that the user may see; "" returns every item. Throws on a malformed query.
getMembers()User[]
getMemberById(userId)User or null
getItemTypes()[{id, name, description, icon}]
getStatuses(itemTypeId)[{id, name, color, icon, enabled}]statuses are per item type
getFields(itemTypeId)[{id, name, description, type, icon}]built-in and custom fields together
getCustomFields(itemTypeId)[{id, name, description, type}]
getDefaultFields(itemTypeId)[{id, name, description, type, icon}]enabled built-in fields

Backend scripts only:

MethodReturns
createItem(itemTypeId, data)result with itemIddata keys: title, description, status, assignee (user id), dueDate (RFC 3339 string), customFields ({fieldId: value}, values as in Field values)
deleteItem(itemId)resultmoves the item to the trash
save()resultkept for compatibility; writes nothing (fails when you may not update the group)
const res = group.createItem("task", {
  title: "Follow up with ACME",
  assignee: userId,
  dueDate: "2026-10-01T00:00:00Z",
  customFields: { priority: "high" }
});
if (res.success) log("created", res.itemId);

In backend scripts, the items returned by queryItems are writable: every item method below is available on them.

item#

The item in scope (see the overview for which scripts have one), and every element returned by group.queryItems.

PropertyType
idstring
titlestring
descriptionstringHTML
statusstringstatus id, "" when unset
typestringitem type id
groupIdstring
idInGroupnumber
tagstringhuman-readable id, e.g. PRJ-12 or #12
createdBystringauthor’s user id
assignedTostringassignee’s user id, "" when unassigned
isCompletedboolean
createdAt, updatedAt, dueDate, completedAtstring or nullISO 8601, e.g. "2026-05-06T00:00:00Z" — wrap in new Date(…) to compare
MethodReturns
getField(fieldId)a plain valueany built-in or custom field — see Field values
renderField(fieldId)stringthe field’s value as the app renders it, in HTML
readAttachment(attachmentId)filea file’s metadata with text(), base64() and bytes() — see Files and attachments. Throws when the file is not on the item.

Backend scripts only — each returns a result:

Method
setField(fieldId, value)set any field; values as in Field values; null clears
setTitle(title)
setDescription(html)
setStatus(statusId)
setAssignedTo(userId)"" unassigns
setDueDate(isoDateTime)an RFC 3339 string such as "2026-08-01T00:00:00Z"; "" clears. For a plain date use setField("dueDate", "2026-08-01").
addAttachment(fieldId, {filename, base64 | text | bytes})result with attachment — see Files and attachments
removeAttachment(fieldId, attachmentId)moves the file to the trash
addComment(text)posts a comment as the script’s user
delete()moves the item to the trash
save()saves the whole item

Setters save immediately; save() is not needed after them. In a save hook, the item’s changes are instead saved together with the change that triggered the hook — see Backend scripts.

Permissions apply as for a person: queryItems only returns items its user may see, a field that user’s roles hide reads as unset — getField returns null (or [] for a list field), properties such as status or dueDate are empty, renderField renders nothing and readAttachment cannot reach its files — and a script cannot change a field its user may not edit. Group administrators see every field.

pageVars#

The variables of the page a chart is shown on, for the current viewer, keyed by variable key. Outside a page — in every backend script — it is empty.

MemberReturns
pageVars.<key>the raw valueboolean, string, number, Date, an item or an array of items
has(key)booleanwhether the variable is defined and set
get(key)the raw value or undefinedalso reaches a variable whose key is has, get, render or display
render(key)stringthe value as the app renders it (user chip, status chip, formatted date), in HTML
display(key)stringthe value as plain text

A date variable set from a relative expression also has <key>_expr (the expression, e.g. "$today-7d") and, when it names a period, <key>_range ({from: Date, to: Date}).

const since = pageVars.has("since") ? pageVars.since : new Date(Date.now() - 7 * 864e5);

api#

In-memory helpers for shaping lists of items.

FunctionReturns
api.groupBy(items, property){value: items[]}groups by a property such as status or assignedTo; items where it is null or missing are left out, and unset status / assignedTo ("") are grouped under ""
api.aggregate(items, property, fn)numberfn is "sum", "avg", "min", "max" or "count"; non-numeric values are skipped
api.filterItems(items, predicate)items[]like Array.prototype.filter

They read item properties. For a custom field, map first: items.map(it => ({ value: it.getField("estimate") })).

echarts#

Helpers that build ECharts options for scripted charts: echarts.createPieChart, createBarChart, createLineChart and createScatterChart. See Scripted charts.

fetch#

Backend scripts only. Makes an HTTP request and returns the response.

const r = fetch("https://api.example.com/orders?status=open", {
  method: "GET",
  headers: { Authorization: "Bearer " + secrets.get("SHOP_TOKEN") }
});
if (!r.ok) throw new Error("shop API answered " + r.status);
const orders = r.json();
Option
methodGET (default), POST, PUT, PATCH, DELETE or HEAD
headersan object of header names to values
bodya string; an object or array, sent as JSON with Content-Type: application/json unless you set one; or an ArrayBuffer / Uint8Array, sent as raw bytes
Response member
status, statusText, okok is true for 2xx
headersresponse headers, keys in lower case
bodythe body as a string
json()the body parsed as JSON; throws if it is not JSON
base64(), bytes()the body as base64 / an ArrayBuffer — use these for files

Only http and https URLs are allowed, and requests to private or loopback addresses are blocked. A request times out after 30 seconds and follows at most 5 redirects; the response is limited to 10 MB. A network failure throws. Each call counts against the script’s API call limit — see Limits and errors.

secrets#

Backend scripts only.

FunctionReturns
secrets.get(key)string or nullthe secret’s value, from the group’s secrets or else the instance’s

Secret values are never written to logs by the platform — do not log them yourself. Each call counts against the API call limit. Secrets are managed under group secrets.

log and console.log#

log(...values) and its alias console.log(...values) write a line to the script’s execution history, which is what you read when a run misbehaves. Strings are written as is, other values as JSON, and null and undefined stay distinguishable.

Script metadata#

GlobalType
userId, groupId, instanceIdstring
scriptId, scriptTypestringscriptType is backend or chart
itemIdstringthe id of item, when there is one
isGroupScoped, isInstanceScoped, isItemScopedboolean