Using REST API to execute karaf commands

  Written by The Jahia Team
 
Sysadmins
   Estimated reading time:

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

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

The endpoint accepts POST request and is only available for the tools users, or a server administrator. 

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

curl -u 'jahia:password' -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 'jahia:password'  -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"
    }, ... 
  ]
}