Reputation: 175
I have a OneSignal notifications integrated to my Web Application it works fine,but the problem is I need to send notification only to a specific user. I will select a email and send the notification. For that OneSignal
provides segment,when I create a segment and give a email ID it says 0 users in the segment.
My question how is the email ID I type in the segment gets compared with and return me 0 users?
Upvotes: 2
Views: 1442
Reputation: 378
Use tag instead. For the person you want to send the message to, set a tag, for example: {email: [email protected]}.
And then in your notification sending code, send to the person based on tag. e.g.
$content = array(
"en" => "hello jimmy"
);
$fields = array(
'app_id' => <your_ID_here> ,
'filters' => array(array("field" => "tag", "key" => "email", "relation" => "=", "value" => "[email protected]")),
'data' => array("foo" => "bar"),
'contents' => $content
);
$fields = json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8','Authorization: Basic '.$_SESSION['global_rest_id']));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
Upvotes: 1