bad request when doing /commands/send of API

Dan Dyse5 years ago

Response: NullPointerException (CommandsManager:58 < CommandResource:71 < ...)

The docs say it means either wrong permission (I doubt, because I'm using admin login and got a list of all devices and custom commands before trying this) or the "type" may be wrong. But it's "custom" so this correct as well, isn't it?!

Using a slightly edited version of traccar-api-php with this:

public static function sendCommand2($deviceId,$type,$attributes,$cookie) {

        $attributes=',"attributes":{"data":"'.$attributes.'"}';
$data='{"deviceId":'.$deviceId.',"type":"'.$type.'","id":-1'.$attributes.'}';

        return self::curl('/api/commands/send','POST',$cookie ,$data,array(self::$json));
    }
Dan Dyse5 years ago

Find it out myself: in order to execute a non-existing (new) custom command, don't set "id" to -1, just leave it out at all instead:

$data='{"deviceId":'.$deviceId.',"type":"custom"'.$attributes.'}';

Before trying this I have just used one existing custom command id combined with new attributes (data to send). This worked as well, not changing the existing command.