Sample Code

In the below code <API_NAME> is the name of the API and PARAMETER_NAME is the name of the Post parameters for the respective API. The PARAMETER_VALUE is the value that you want to pass to the parameter.

$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;

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

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