Using REST API to execute karaf commands

October 8, 2024

Karaf commands can be executed through a REST endpoint, located at:

http://<server>/modules/api/commands

The endpoint accepts POST requests and is only available for users who have permission to use Jahia Tools. For information on Jahia Tools permissions, see Managing roles and permissions.

A simple command can be passed as the last part of the path:

curl -u 'root:root' -X POST  http://localhost:8080/modules/api/commands/bundle:list

If the command contains parameters and you don't want to url-encode it, it can also be passed as plain text content body:

curl -u 'root:root'  -H "content-Type: text/plain" -X POST -d 'bundle:list -t 0 -s' http://localhost:8080/modules/api/commands

The result is sent as a JSON object. It contains an "output" field for plain text answer, and a "resultsTable" if the command was returning a table. For example, the bundle:list command will return something like:

{
  "output": [
    "START LEVEL 100 , List Threshold: 50"
  ],
  "resultsTable": [
    {
      "Lvl":"80",
      "Version":"4.0.7",
      "State":"Active",
      "ID":"18",
      "Name":"Apache Karaf :: Diagnostic :: Boot"
    }, ... 
  ]
}