CommsMundi Public API

The CommsMundi public api allow third party aplications to take control or interect directly with the CommsMundi modules.

To use it you must first activate the api module and configure it on the frontend page (in Home → Frontend) by adding a new site with the application commsmundi public api enabled.

Protocol

The protocol to communicate with CM public api is JSON RPC 2.0, you can check the full specification here.

Authentication

Authentication is done using HTTP BASIC AUTHENTICATION. If the authentication is wrong CM will return 401 Unauthorized

The url must be in the form of http://USERNAME:PASSWORD@CM_SERVER_SITE_ADDRESS

Security

To secure the connection use HTTPS with a valid certificate.

Methods

To get a list of valid methods to use execute the api command help.

  • Example PHP
api_help.php
<?php
$server = "192.168.10.1:444";
$url = "http://administrator:commsmundi@".$server;
 
//get all the available methods
$request = array();
$request['id'] = mt_rand();
$request['jsonrpc'] = "2.0";
$request['method'] = "help";
$data = api_call($url, $request);
print_r($data);
 
// get help usage on a specific method
$request = array();
$request['id'] = mt_rand();
$request['jsonrpc'] = "2.0";
$request['method'] = "help";
$request['params'] = array();
$request['params']['method_name'] = "dir_get";
$data = api_call($url, $request);
print_r($data);
 
function api_call($url, $request)
{
	$headers = array(
		"Connection: close",
		"Content-Type: application/json",
		"Accept: application/json");
 
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1800);
	curl_setopt($ch, CURLOPT_USERAGENT, 'JSON-RPC PHP Client');
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
	curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
	$http_body = curl_exec($ch);
	$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	if ($http_code === 401 || $http_code === 403) {
		return false;
	}
	return json_decode($http_body, true);
}
?>
/home/www/wiki/data/pages/documentation/api.txt · Last modified: 2015/10/16 15:27 by admin
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki