Class

ApiController

ApiController

Controller responsible for the auto-generated API: /admin_root/api/..., where admin_root is the rootPath given in AdminJSOptions.

The best way to utilise it is to use ApiClient on the frontend.

Available API endpoints

Endpoint Method Description
.../api/resources/{resourceId}/actions/{action} ApiController#resourceAction Perform customized resource action
.../api/resources/{resourceId}/records/{recordId}/{action} ApiController#recordAction Perform customized record action
.../api/resources/{resourceId}/bulk/{action}?recordIds={recordIds} ApiController#bulkAction Perform customized bulk action
.../api/pages/{pageName}_ ApiController#page Perform customized page action
.../api/dashboard_ ApiController#dashboard Perform customized dashboard action

Responsibility

In general this controllers takes handler functions you define in AdminJSOptions and:

You probably don't want to modify it, but you can call its methods by using ApiClient

Classes

ApiController

Methods

# async bulkAction(request, response) → {Promise.<BulkActionResponse>}

Performs a customized bulk action.

To call it use ApiClient#bulkAction method.

Handler function responsible for a .../api/resources/{resourceId}/bulk/{action}?recordIds={recordIds}

Parameters:
Name Type Description
request ActionRequest
response any

View Source adminjs/src/backend/controllers/api-controller.ts, line 332

NotFoundError when recordIds are missing in query or they don't exists in the database

ConfigurationError when action handler doesn't return Promise<BulkActionResponse>

action response

Promise.<BulkActionResponse>

# async dashboard(request, response) → {Promise.<any>}

Gets optional data needed by the dashboard.

To call it use ApiClient#getDashboard method.

Handler function responsible for a .../api/dashboard

Parameters:
Name Type Description
request ActionRequest
response any

View Source adminjs/src/backend/controllers/api-controller.ts, line 346

action response

Promise.<any>

# async page(request, response) → {Promise.<any>}

Gets optional data needed by the page.

To call it use ApiClient#getPage method.

Handler function responsible for a .../api/pages/{pageName}

Parameters:
Name Type Description
request ActionRequest
response any

View Source adminjs/src/backend/controllers/api-controller.ts, line 360

action response

Promise.<any>

# async recordAction(originalRequest, response) → {Promise.<RecordActionResponse>}

Performs a customized record action.

To call it use ApiClient#recordAction method.

Handler function responsible for a .../api/resources/{resourceId}/records/{recordId}/{action}

Parameters:
Name Type Description
originalRequest ActionRequest
response any

View Source adminjs/src/backend/controllers/api-controller.ts, line 315

ConfigurationError When given record action doesn't return RecordJSON

ConfigurationError when action handler doesn't return Promise<RecordActionResponse>

action response

Promise.<RecordActionResponse>

# async resourceAction(originalRequest, response) → {Promise.<ActionResponse>}

Performs a customized resource action.

To call it use ApiClient#resourceAction method.

Handler function responsible for a .../api/resources/{resourceId}/actions/{action}

Parameters:
Name Type Description
originalRequest ActionRequest
response any

object from the plugin (i.e. adminjs-expressjs)

View Source adminjs/src/backend/controllers/api-controller.ts, line 299

action response

Promise.<ActionResponse>
Search records by query string.

Handler function responsible for a .../api/resources/{resourceId}/search/{query} route

Parameters:
Name Type Description
request ActionRequest

with params.query set

response any

View Source adminjs/src/backend/controllers/api-controller.ts, line 285

found records

Promise.<SearchActionResponse>