Advice and answers from the Realtime Team

The Realtime REST API provides a sendbatch endpoint, accepting a message and a set of channels (max of 100 channels for request).

Here's an example in PHP to send a 

{"foo":"bar"}

 message to channels channel1, channel2 and channel3:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://ortc-developers-useast1-s0001.realtime.co/sendbatch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"content-type: application/x-www-form-urlencoded"
),

CURLOPT_POSTFIELDS => 'AK=YOUR-REALTIME-APPKEY&PK=YOUR-REALTIME-PRIVATE-KEY&C=channel1,channel2,channel3&M=12345678_1-1_{"foo":"bar"}'
));

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

?>

Don't forget to enter your Realtime application key in the AK argument and the private key in the PK argument.

You can also use the AT argument and pass an authenticated token with write permissions for all channels in argument C instead of using the private key).

More details about the REST API can be found at http://messaging-public.realtime.co/documentation/rest/2.1.0/RestServices.pdf

Did this answer your question?