@@ -347,13 +347,110 @@ List Commands of a Device
347347
348348 GET /api/v1/controller/device/{device_id}/command/
349349
350+ .. _controller_execute_command_api :
351+
350352Execute a Command on a Device
351353~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352354
353355.. code-block :: text
354356
355357 POST /api/v1/controller/device/{device_id}/command/
356358
359+ This endpoint allows you to execute various types of commands on a device.
360+
361+ **Request Parameters **
362+
363+ ============== ========================================================
364+ Parameter Description
365+ ============== ========================================================
366+ ``type `` The type of command to execute (**required **)
367+ ``input `` Input data for the command (format varies by type)
368+ (**required **)
369+ ``connection `` UUID of specific device connection to use (**optional **)
370+ ============== ========================================================
371+
372+ The ``input `` field requires data in a specific format that depends on the
373+ command type being executed.
374+
375+ .. note ::
376+
377+ The following examples show payloads for the default commands shipped
378+ with OpenWISP. The available commands on a device depend on your
379+ configuration of :ref: `OPENWISP_CONTROLLER_USER_COMMANDS
380+ <openwisp_controller_user_commands>` and
381+ :ref: `OPENWISP_CONTROLLER_ORGANIZATION_ENABLED_COMMANDS ` settings. For
382+ detailed information about command execution, including how to add
383+ command types, and restrict available commands per organization, see
384+ :doc: `shell-commands `.
385+
386+ **Available Command Types **
387+
388+ 1. **Custom Command ** (``custom ``)
389+
390+ Execute a custom command on the device.
391+
392+ **Input format: ** ``{"command": "shell_command"} ``
393+
394+ **Example payload: **
395+
396+ .. code-block :: json
397+
398+ {
399+ "type" : " custom" ,
400+ "input" : {
401+ "command" : " iwinfo"
402+ }
403+ }
404+
405+ 2. **Reboot ** (``reboot ``)
406+
407+ Reboot the device.
408+
409+ **Input format: ** ``null `` (no input required)
410+
411+ **Example payload: **
412+
413+ .. code-block :: json
414+
415+ {
416+ "type" : " reboot" ,
417+ "input" : null
418+ }
419+
420+ 3. **Change Password ** (``change_password ``)
421+
422+ Change the device's root password.
423+
424+ **Input format: ** ``{"password": "new_pass", "confirm_password":
425+ "new_pass"} ``
426+
427+ **Example payload: **
428+
429+ .. code-block :: json
430+
431+ {
432+ "type" : " change_password" ,
433+ "input" : {
434+ "password" : " newpassword123" ,
435+ "confirm_password" : " newpassword123"
436+ }
437+ }
438+
439+ **Example Request: **
440+
441+ .. code-block :: shell
442+
443+ curl -X POST \
444+ http://127.0.0.1:8000/api/v1/controller/device/76b7d9cc-4ffd-4a43-b1b0-8f8befd1a7c0/command/ \
445+ -H ' authorization: Bearer yoursecretauthtoken' \
446+ -H ' content-type: application/json' \
447+ -d ' {
448+ "type": "custom",
449+ "input": {
450+ "command": "uptime"
451+ }
452+ }'
453+
357454 Get Command Details
358455~~~~~~~~~~~~~~~~~~~
359456
0 commit comments