docs/Script API/interfaces/Backend_Script_API.Api.html
interface Api {
__private: { becca: default };
axios: AxiosStatic;
cheerio: {
default: CheerioAPI;
version: string;
contains(container: Element, contained: Element): boolean;
html(options?: CheerioParserOptions): string;
html(
dom: string | Element | Cheerio,
options?: CheerioParserOptions,
): string;
load(
html: string | Buffer<ArrayBufferLike>,
options?: CheerioParserOptions,
): Root;
load(element: Element | Element[], options?: CheerioParserOptions): Root;
parseHTML(
data: string,
context?: null | Document,
keepScripts?: boolean,
): Document[];
root(): Cheerio;
xml(dom?: string | Element | Cheerio): string;
};
currentNote: BNote;
dayjs: __module;
logMessages: Record<string, string[]>;
logSpacedUpdates: Record<string, SpacedUpdate>;
originEntity?: null | AbstractBeccaEntity<any>;
sql: any;
startNote?: null | BNote;
xml2js: node_modules/@types/xml2js;
backupNow(backupName: string): Promise<string>;
createDataNote(
parentNoteId: string,
title: string,
content: {},
): NoteAndBranch;
createNewNote(params: NoteParams): NoteAndBranch;
createNote(
parentNoteId: string,
title: string,
content: string,
extraOptions: Omit<
NoteParams,
"title"
| "parentNoteId"
| "content"
| "type",
> & { attributes?: AttributeRow[]; json?: boolean },
): NoteAndBranch;
createOrUpdateLauncher(
opts: {
icon: string;
id: string;
isVisible: boolean;
keyboardShortcut: string;
scriptNoteId: string;
targetNoteId: string;
title: string;
type: "script" | "note" | "customWidget";
widgetNoteId?: string;
},
): { note: BNote };
createTextNote(
parentNoteId: string,
title: string,
content: string,
): NoteAndBranch;
ensureNoteIsAbsentFromParent(noteId: string, parentNoteId: string): void;
ensureNoteIsPresentInParent(
noteId: string,
parentNoteId: string,
prefix: string,
): { branch: null | BBranch };
escapeHtml(string: string): string;
exportSubtreeToZipFile(
noteId: string,
format: "html" | "markdown",
zipFilePath: string,
): Promise<void>;
getAppInfo(): {
appVersion: string;
buildDate: string;
buildRevision: string;
clipperProtocolVersion: string;
dataDirectory: string;
dbVersion: number;
nodeVersion: string;
syncVersion: number;
utcDateTime: string;
};
getAttachment(attachmentId: string): null | BAttachment;
getAttribute(attachmentId: string): null | BAttribute;
getAttribute(attributeId: string): null | BAttribute;
getBranch(branchId: string): null | BBranch;
getDayNote(date: string, rootNote?: BNote): Promise<null | BNote>;
getEtapiToken(etapiTokenId: string): null | BEtapiToken;
getEtapiTokens(): BEtapiToken[];
getInstanceName(): null | string;
getMonthNote(date: string, rootNote: BNote): Promise<null | BNote>;
getNote(noteId: string): null | BNote;
getNotesWithLabel(name: string, value?: string): BNote[];
getNoteWithLabel(name: string, value?: string): null | BNote;
getOption(optionName: string): null | BOption;
getOptions(): BOption[];
getQuarterNote(date: string, rootNote: BNote): Promise<null | BNote>;
getRevision(revisionId: string): null | BRevision;
getRootCalendarNote(): null | BNote;
getTodayNote(rootNote?: BNote): Promise<null | BNote>;
getWeekFirstDayNote(date: string, rootNote: BNote): Promise<null | BNote>;
getWeekNote(date: string, rootNote: BNote): Promise<null | BNote>;
getYearNote(year: string, rootNote?: BNote): null | BNote;
log(message: string): void;
randomString(length: number): string;
runOnFrontend(script: () => string | void, params: []): void;
runOutsideOfSync(callback: () => void): Promise<void>;
searchForNote(query: string, searchParams: SearchParams): null | BNote;
searchForNotes(query: string, searchParams: SearchParams): BNote[];
setNoteToParent(
noteId: string,
prefix: string,
parentNoteId: null | string,
): void;
sortNotes(
parentNoteId: string,
sortConfig: { foldersFirst?: boolean; reverse?: boolean; sortBy?: string },
): void;
toggleNoteInParent(
present: true,
noteId: string,
parentNoteId: string,
prefix: string,
): void;
transactional(func: () => void): any;
unescapeHtml(string: string): string;
}
__privateaxioscheeriocurrentNotedayjslogMessageslogSpacedUpdatesoriginEntity?sqlstartNote?xml2js
backupNowcreateDataNotecreateNewNotecreateNotecreateOrUpdateLaunchercreateTextNoteensureNoteIsAbsentFromParentensureNoteIsPresentInParentescapeHtmlexportSubtreeToZipFilegetAppInfogetAttachmentgetAttributegetBranchgetDayNotegetEtapiTokengetEtapiTokensgetInstanceNamegetMonthNotegetNotegetNotesWithLabelgetNoteWithLabelgetOptiongetOptionsgetQuarterNotegetRevisiongetRootCalendarNotegetTodayNotegetWeekFirstDayNotegetWeekNotegetYearNotelograndomStringrunOnFrontendrunOutsideOfSyncsearchForNotesearchForNotessetNoteToParentsortNotestoggleNoteInParenttransactionalunescapeHtml
__private: { becca: default }
This object contains "at your risk" and "no BC guarantees" objects for advanced use cases.
provides access to the backend in-memory object graph, see Becca
axios: AxiosStatic
Axios library for HTTP requests. See https://axios-http.com for documentation
use native (browser compatible) fetch() instead
cheerio: {
default: CheerioAPI;
version: string;
contains(container: Element, contained: Element): boolean;
html(options?: CheerioParserOptions): string;
html(
dom: string | Element | Cheerio,
options?: CheerioParserOptions,
): string;
load(
html: string | Buffer<ArrayBufferLike>,
options?: CheerioParserOptions,
): Root;
load(element: Element | Element[], options?: CheerioParserOptions): Root;
parseHTML(
data: string,
context?: null | Document,
keepScripts?: boolean,
): Document[];
root(): Cheerio;
xml(dom?: string | Element | Cheerio): string;
}
cheerio library for HTML parsing and manipulation. See https://cheerio.js.org for documentation
currentNote: BNote
Note where the script is currently executing. This comes into play when your script is spread in multiple code notes, the script starts in "startNote", but then through function calls may jump into another note (currentNote). A similar concept in C would be FILE Don't mix this up with the concept of active note.
dayjs: __module
day.js library for date manipulation. See https://day.js.org for documentation
logMessages: Record<string, string[]>
logSpacedUpdates: Record<string, SpacedUpdate>
OptionaloriginEntityoriginEntity?: null | AbstractBeccaEntity<any>
Entity whose event triggered this execution
sql: any
sql
OptionalstartNotestartNote?: null | BNote
Note where the script started executing (entrypoint). As an analogy, in C this would be the file which contains the main() function of the current process.
xml2js: node_modules/@types/xml2js
xml2js library for XML parsing. See https://github.com/Leonidas-from-XIV/node-xml2js for documentation
backupNow(backupName: string): Promise<string>
If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file
resolves once the backup is finished
createDataNote(parentNoteId: string, title: string, content: {}): NoteAndBranch
Create data note - data in this context means object serializable to JSON. Created note will be of type 'code' and JSON MIME type. See also createNewNote() for more options.
createNewNote(params: NoteParams): NoteAndBranch
object contains newly created entities note and branch
createNote(
parentNoteId: string,
title: string,
content: string,
extraOptions: Omit<
NoteParams,
"title"
| "parentNoteId"
| "content"
| "type",
> & { attributes?: AttributeRow[]; json?: boolean },
): NoteAndBranch
create new note under this parent
Optionalattributes?: AttributeRow[]-
Optionaljson?: booleanshould the note be JSON
object contains newly created entities note and branch
please use createTextNote() with similar API for simpler use cases or createNewNote() for more complex needs
createOrUpdateLauncher(
opts: {
icon: string;
id: string;
isVisible: boolean;
keyboardShortcut: string;
scriptNoteId: string;
targetNoteId: string;
title: string;
type: "script" | "note" | "customWidget";
widgetNoteId?: string;
},
): { note: BNote }
Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.
name of the boxicon to be used (e.g. "bx-time")
-
id of the launcher, only alphanumeric at least 6 characters long
-
if true, will be created in the "Visible launchers", otherwise in "Available launchers"
-
will activate the target note/script upon pressing, e.g. "ctrl+e"
-
for type "script"
-
for type "note"
-
-
one of
- "note" - activating the launcher will navigate to the target note (specified in targetNoteId param)
- "script" - activating the launcher will execute the script (specified in scriptNoteId param)
- "customWidget" - the launcher will be rendered with a custom widget (specified in widgetNoteId param)
-
OptionalwidgetNoteId?: stringfor type "customWidget"
createTextNote(
parentNoteId: string,
title: string,
content: string,
): NoteAndBranch
Create text note. See also createNewNote() for more options.
ensureNoteIsAbsentFromParent(noteId: string, parentNoteId: string): void
If there's a branch between note and parent note, remove it. Otherwise, do nothing.
ensureNoteIsPresentInParent(
noteId: string,
parentNoteId: string,
prefix: string,
): { branch: null | BBranch }
If there's no branch between note and parent note, create one. Otherwise, do nothing. Returns the new or existing branch.
if branch is created between note and parent note, set this prefix
escapeHtml(string: string): string
escaped string
exportSubtreeToZipFile(
noteId: string,
format: "html" | "markdown",
zipFilePath: string,
): Promise<void>
either 'html' or 'markdown'
getAppInfo(): {
appVersion: string;
buildDate: string;
buildRevision: string;
clipperProtocolVersion: string;
dataDirectory: string;
dbVersion: number;
nodeVersion: string;
syncVersion: number;
utcDateTime: string;
}
getAttachment(attachmentId: string): null | BAttachment
getAttribute(attachmentId: string): null | BAttribute
getAttribute(attributeId: string): null | BAttribute
getBranch(branchId: string): null | BBranch
getDayNote(date: string, rootNote?: BNote): Promise<null | BNote>
Returns day note for given date. If such note doesn't exist, it is created.
in YYYY-MM-DD format
OptionalrootNote: BNotespecify calendar root note, normally leave empty to use the default calendar
getEtapiToken(etapiTokenId: string): null | BEtapiToken
getEtapiTokens(): BEtapiToken[]
getInstanceName(): null | string
Instance name identifies particular Trilium instance. It can be useful for scripts if some action needs to happen on only one specific instance.
getMonthNote(date: string, rootNote: BNote): Promise<null | BNote>
Returns month note for given date. If such a note doesn't exist, it is created.
in YYYY-MM format
specify calendar root note, normally leave empty to use the default calendar
getNote(noteId: string): null | BNote
getNotesWithLabel(name: string, value?: string): BNote[]
Retrieves notes with given label name & value
attribute name
Optionalvalue: stringattribute value
getNoteWithLabel(name: string, value?: string): null | BNote
Retrieves first note with given label name & value
attribute name
Optionalvalue: stringattribute value
getOption(optionName: string): null | BOption
getOptions(): BOption[]
getQuarterNote(date: string, rootNote: BNote): Promise<null | BNote>
Returns quarter note for given date. If such a note doesn't exist, it is created.
in YYYY-MM format
specify calendar root note, normally leave empty to use the default calendar
getRevision(revisionId: string): null | BRevision
getRootCalendarNote(): null | BNote
Returns root note of the calendar.
getTodayNote(rootNote?: BNote): Promise<null | BNote>
Returns today's day note. If such note doesn't exist, it is created.
OptionalrootNote: BNotespecify calendar root note, normally leave empty to use the default calendar
getWeekFirstDayNote(date: string, rootNote: BNote): Promise<null | BNote>
Returns note for the first date of the week of the given date.
in YYYY-MM-DD format
specify calendar root note, normally leave empty to use the default calendar
getWeekNote(date: string, rootNote: BNote): Promise<null | BNote>
Returns week note for given date. If such a note doesn't exist, it is created.
in YYYY-MM-DD format
specify calendar root note, normally leave empty to use the default calendar
getYearNote(year: string, rootNote?: BNote): null | BNote
Returns year note for given year. If such a note doesn't exist, it is created.
in YYYY format
OptionalrootNote: BNotespecify calendar root note, normally leave empty to use the default calendar
log(message: string): void
Log given message to trilium logs and log pane in UI
randomString(length: number): string
Return randomly generated string of given length. This random string generation is NOT cryptographically secure.
of the string
random string
runOnFrontend(script: () => string | void, params: []): void
Executes given anonymous function on the frontend(s). Internally, this serializes the anonymous function into string and sends it to frontend(s) via WebSocket. Note that there can be multiple connected frontend instances (e.g. in different tabs). In such case, all instances execute the given function.
script to be executed on the frontend
list of parameters to the anonymous function to be sent to frontend
no return value is provided.
runOutsideOfSync(callback: () => void): Promise<void>
Sync process can make data intermittently inconsistent. Scripts which require strong data consistency can use this function to wait for a possible sync process to finish and prevent new sync process from starting while it is running.
Because this is an async process, the inner callback doesn't have automatic transaction handling, so in case you need to make some DB changes, you need to surround your call with api.transactional(...)
function to be executed while sync process is not running
resolves once the callback is finished (callback is awaited)
searchForNote(query: string, searchParams: SearchParams): null | BNote
This is a powerful search method - you can search by attributes and their values, e.g.: "#dateModified =* MONTH AND #log". See https://triliumnext.github.io/Docs/Wiki/search.html for full documentation for all options
searchForNotes(query: string, searchParams: SearchParams): BNote[]
This is a powerful search method - you can search by attributes and their values, e.g.: "#dateModified =* MONTH AND #log". See https://triliumnext.github.io/Docs/Wiki/search.html for full documentation for all options
setNoteToParent(
noteId: string,
prefix: string,
parentNoteId: null | string,
): void
This method finds note by its noteId and prefix and either sets it to the given parentNoteId or removes the branch (if parentNoteId is not given).
This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix.
this method is pretty confusing and serves specialized purpose only
sortNotes(
parentNoteId: string,
sortConfig: { foldersFirst?: boolean; reverse?: boolean; sortBy?: string },
): void
Sort child notes of a given note.
OptionalfoldersFirst?: boolean-
Optionalreverse?: boolean-
OptionalsortBy?: string'title', 'dateCreated', 'dateModified' or a label name See https://triliumnext.github.io/Docs/Wiki/sorting.html for details.
toggleNoteInParent(
present: true,
noteId: string,
parentNoteId: string,
prefix: string,
): void
Based on the value, either create or remove branch between note and parent note.
true if we want the branch to exist, false if we want it gone
if branch is created between note and parent note, set this prefix
transactional(func: () => void): any
This functions wraps code which is supposed to be running in transaction. If transaction already exists, then we'll use that transaction.
result of func callback
unescapeHtml(string: string): string
to unescape
unescaped string
Member Visibility
ThemeOSLightDark
Properties __privateaxioscheeriocurrentNotedayjslogMessageslogSpacedUpdatesoriginEntitysqlstartNotexml2js Methods backupNowcreateDataNotecreateNewNotecreateNotecreateOrUpdateLaunchercreateTextNoteensureNoteIsAbsentFromParentensureNoteIsPresentInParentescapeHtmlexportSubtreeToZipFilegetAppInfogetAttachmentgetAttributegetBranchgetDayNotegetEtapiTokengetEtapiTokensgetInstanceNamegetMonthNotegetNotegetNotesWithLabelgetNoteWithLabelgetOptiongetOptionsgetQuarterNotegetRevisiongetRootCalendarNotegetTodayNotegetWeekFirstDayNotegetWeekNotegetYearNotelograndomStringrunOnFrontendrunOutsideOfSyncsearchForNotesearchForNotessetNoteToParentsortNotestoggleNoteInParenttransactionalunescapeHtml