Skip to content
This page View Markdown Open in ChatGPT Open in Claude

Code examples

Custom APIs, hooks, events, schedulers, migrations, process initializers and test cases all receive the same global object g. Every page of this section is one method of it, with a snippet you can paste into the editor of the admin panel.

Every snippet has the same shape :

1
2
3
4
5
6
7
8
import * as T from 'types';          // the types of API Maker
import * as db from 'db-interfaces'; // the interfaces generated from your schemas

async function main(g: T.IAMGlobal) {
    // your code, with await on every call of g.sys
    return { hello: 'world' };       // what the caller receives in data
}
module.exports = main;

The second argument

Every g.sys call takes an optional second argument. With true, the call returns the whole response envelope and never throws : const res = await g.sys.db.count({ ... }, true); if (!res.success) .... Without it, the call returns data and throws the errors, so the caller of your API gets them.