Sample Code

To check the list of API names and POST parameters for an API, you can refer API Table.

$url = "http://PATH_TO_COMETCHAT_DIRECTORY/cometchat/api/index.php";
$fields = array("action"=>"API_NAME","PARAMETER_NAME"=>"PARAMETER_VALUE");
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.($value).'&'; }
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('api-key: API_KEY'));
$result = curl_exec($ch);
if (empty($result)) {
    die(curl_error($ch));
}
curl_close ($ch);
echo $result;

Where:
API_NAME: name of API eg. createuser.
PARAMETER_NAME: name of the POST parameters eg. “api-key”, “userid”, “username”, etc.
PARAMETER_VALUE: the value that you want to pass to that parameter.
PATH_TO_COMETCHAT_DIRECTORY: path to CometChat directory eg. www.yoursite.com/forum

Example:
If you want to use “createuser” API then the cURL code will be as follows:

$url = "http://www.yoursite.com/cometchat/api/index.php";
$fields = array("action"=>"createuser",api-key=>”API_KEY”,"username"=>"xyz","password"=>"123");
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.($value).'&'; }
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('api-key:API_KEY'));
$result = curl_exec($ch);
if (empty($result)) {
    die(curl_error($ch));
}
curl_close ($ch);
echo $result;

Not finding what you need?

The CometChat team is here to help!