Sample Code

Product:

Sample Code

$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

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

Sample Code

$url = "http://api.cometondemand.net/api/";
$fields = array("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

Name Description Mandatory
URL API url. for eg. for create user api url will be http://api.cometondemand.net/api/createuser Yes
PARAMETER_NAME name of the POST parameters eg. “username”, etc. Yes
PARAMETER_VALUE the value that you want to pass to that parameter Yes
API_KEY The API Key present in your CometChat Admin Panel Yes
  • Was this helpful?
  • Yes   No