Learn more
Links
ReferenceAdvancedAdmin

Custom commands

Call a service a device registered on its own side, by name and with any JSON parameters, from the Device Terminal, the Links CLI or a server.

7 min read0 viewsUpdated 2026-11-13

What custom commands are

A custom command is a service a device registers on its own side, under a name you choose, without telling Links about it first. A Links admin calls it by name, with any JSON parameters, from:

  • the Device Terminal in the admin panel,
  • the Links CLI (/call in the terminal, or links run ... /call in a script),
  • a server (the Links API endpoint POST /api/devices/customCommand).

The device runs its handler and answers with a result or an error. Links checks who calls and the shape of the call, then carries it; it does not read or change the parameters or the answer.

Who may callLinks admins only. Workspace admins and members cannot send custom commands from any surface.
What the device declaresNothing. A name with no handler on the device answers UNIMPLEMENTED.
Offline deviceRefused at once with UNAVAILABLE. Custom commands are never queued for later.
ModelRequest and response by name, like Azure IoT Hub Direct Methods; answers shaped like JSON-RPC 2.0; error codes from gRPC.

Names and the message on the wire

A command name is 1 to 4 lowercase parts joined by dots, at most 64 characters: letters, digits, - and _, starting with a letter. Examples: diagnostics.ping, cache.clear, printer.calibrate, relay.pulse.

On the wire the command type is custom. followed by the name. The custom. prefix is reserved, so a custom command never collides with a built-in one (smartDisplay.*, podGateway.*, device.*).

The device receives the usual command message. payload is exactly what the caller sent (a JSON object, at most 8 KB):

{
  "type": "command",
  "commandId": "8f1c2a90-3b4e-4c55-9d1e-2f6a7b8c9d0e",
  "commandType": "custom.printer.calibrate",
  "payload": { "mode": "full", "speed": 3, "heads": [1, 2] },
  "source": "admin",
  "initiatedBy": "42",
  "version": 1
}

Register a command on the device

With the Links device SDK (web screens and the Space Display app), register a handler by name on the command service. The value the handler returns is the answer; a thrown CustomCommandError sends an error with its code.

import { CommandService, CustomCommandError } from "@/sdk/device/CommandService";

commands
  .onCustomCommand("cache.clear", async (params) => {
    const freedMb = await clearCache(params.keepImages === true);
    return { freedMb };
  })
  .onCustomCommand("printer.calibrate", async (params) => {
    if (await trayIsOpen()) {
      throw new CustomCommandError("FAILED_PRECONDITION", "Paper tray is open", { tray: 2 });
    }
    return { offsetMm: await calibrate(String(params.mode ?? "quick")) };
  });
commands.start();

The SDK answers every custom.* command: executed with the handler's return value, failed with the error, and UNIMPLEMENTED for a name that has no handler. Every web screen already answers diagnostics.ping, which returns the parameters it got back as echo, so you can test the whole round trip.

Without the SDK (gateways, other firmware), read the command message and answer with commandAck on the same socket, using the same commandId. The detail field carries result or error (at most 64 KB):

{ "type": "commandAck", "commandId": "8f1c2a90-...", "status": "executed",
  "detail": { "result": { "offsetMm": 0.4 } } }
{ "type": "commandAck", "commandId": "8f1c2a90-...", "status": "failed",
  "detail": { "error": { "code": "FAILED_PRECONDITION", "message": "Paper tray is open", "data": { "tray": 2 } } } }

For work that takes longer, the device may first send status: "accepted" and later the final executed or failed with the same commandId. The caller waits for the final answer until its timeout.

A device that receives the same commandId twice must run it only once: the id is the call's idempotency key.

Call from the Device Terminal

Open Admin > Devices, select the device and open the Console tab. Type /call, the name, then the parameters as key=value pairs or one JSON object:

> /call diagnostics.ping hello=world
> /call printer.calibrate mode=full speed=3 dryRun=true
> /call printer.calibrate {"mode":"full","heads":[1,2]}

Values are read as JSON when they can be (3, true, null, [1,2], "a b") and as text otherwise. The device's answer appears in the console as its commandAck.

Call from the Links CLI

Sign in with a Links admin account (links login). In the terminal, connect to the device and call the command; the answer is printed in full:

$ links
links> /connect 3f9a1c2e
Connected to Meeting Room Display 3f9a1c2e (smartDisplay, online).
links:meeting-room-display> /call diagnostics.ping hello=world
sent custom.diagnostics.ping {"hello":"world"} commandId=8f1c2a90-...
diagnostics.ping {
"pong": true,
"echo": { "hello": "world" },
"runtime": "web"
}

In a script or from an AI agent, links run sends one call, waits for the answer and exits:

$ links run 3f9a1c2e /call diagnostics.ping hello=world --json
{"ok":true,"exitCode":0,"target":{"kind":"device","id":"3f9a1c2e",...},"command":"custom.diagnostics.ping","params":{"hello":"world"},"commandId":"8f1c2a90-...","result":{"pong":true,...}}
$ links run 3f9a1c2e /call printer.calibrate --params @input.json --timeout 60
Option
key=value ...Parameters, one word each
--params <json> or --params @file.jsonParameters as one JSON object, inline or from a file
--timeout <seconds>How long to wait for the answer (1-300, default 15)
--jsonOne JSON object: result or error {code, message}

Exit codes: 0 the device answered with a result, 1 error (offline device, bad name or parameters), 3 not a Links admin, 5 the device answered with an error, 6 no answer in time.

Call from a server

POST /api/devices/customCommand with the signed-in Links admin's token (the Usertoken header, a dashboard session or a Links CLI token):

curl -X POST https://api.linkspowered.com/en/api/devices/customCommand/ \
  -H "Usertoken: $LINKS_TOKEN" -H "Content-Type: application/json" \
  -d '{"device":"3f9a1c2e-...","name":"printer.calibrate","payload":{"mode":"full"},"wait":true,"timeoutSec":30}'
Field
deviceThe device's uuid
nameThe command name, without custom.
payloadThe parameters, a JSON object (at most 8 KB)
waittrue: wait for the device's answer and return it. false (default): return 202 with the commandId at once
timeoutSecHow long to wait (1-300, default 15)

With wait, the answer is {"success":true,"commandId":"...","status":"executed","result":{...}}, or status: "failed" with error, or status: "timeout" with DEADLINE_EXCEEDED. A refused call answers {"success":false,"error":{"code":"...","message":"..."}}.

Error codes

CodeSent byWhen
PERMISSION_DENIEDLinksThe caller is not a Links admin
INVALID_ARGUMENTLinks or deviceThe name does not follow the rules, the parameters are not a JSON object or are over 8 KB, or the device rejects a parameter
NOT_FOUNDLinksNo such device
UNAVAILABLELinksThe device is offline
DEADLINE_EXCEEDEDLinksNo answer before the timeout
UNIMPLEMENTEDDeviceThe device has no handler for this name
FAILED_PRECONDITIONDeviceThe device cannot do it now (for example a cover is open)
RESOURCE_EXHAUSTEDLinks or deviceToo many calls, or the device is busy
INTERNALDeviceThe handler failed

Every call goes through the device command channel: who sent it, when, with which parameters and what the device answered stays on the device's stream and in the command records.

custom commandsdevicesclisdkapideveloper

Transform your workspace
infrastructure today

Enterprise-grade workspace management with intelligent automation, real-time analytics, and seamless hardware integration.

Enterprise-grade security99.9% uptime SLADedicated support