exec_cmd

To send a command to a unit, use the unit/exec_cmd method.

Endpoint

Copied!
svc=unit/exec_cmd&params={
  "itemId": <long>,
  "commandName": "<text>",
  "linkType": "<text>",
  "param": "<text>",
  "timeout": <uint>,
  "flags": <uint>
}

Parameters

The required parameters are marked with an asterisk (*).

Parameter Description
itemId* Unit ID.
commandName* Command name.
linkType* Link type (see unit/update_command_definition). If the link type is specified in the command properties, the command is sent over that link type, and the value of this parameter is ignored. If the link type is empty both in the request and in the command properties, the link type is selected automatically from those over which the command is currently available.
param* Command parameters. If the command has no parameters, specify an empty string. If the parameters are specified in the command properties, they’re used, and the value of this parameter is ignored.
timeout* Timeout for the command to be in the command queue, in seconds.
flags Flags for selecting a phone number to execute the command:
  • 0: use any (primary, then secondary);
  • 0x1: use primary;
  • 0x2: use secondary;
  • 0x10: send param in JSON format.
If the value isn’t 0, it replaces the lowest byte (0x01–0xFF) of the flags specified in the command properties, and the other flags are taken from the command properties. If the parameter isn’t specified or is 0, the flags from the command properties are used.

Response

If the request is completed successfully, an empty object is returned:

Copied!
{}

If the request fails, an error code is returned.

Error codes

Error code Description
4 Wrong input parameters, for example, one of the required parameters is missing.
5 Failed to execute the command. This error is returned in the following cases:
  • the unit has no command with the specified name;
  • the user doesn’t have the access rights required to execute this command (set in the command properties);
  • the command isn’t currently available over the link type used, for example, the link type doesn’t exist, the unit has no valid phone number for sending SMS, or the device type doesn’t support this command over this link type;
  • the command couldn’t be queued, for example, because the unit isn’t connected over TCP.
7 The unit doesn’t exist, or the user doesn’t have the Send commands access right to it.

If you find a mistake in the text, please select it and press Ctrl+Enter.