User Login

Please enter user name and password into following boxes!

If you are not registered yet, please click

Forget Password

If you forget your password, please click
favorite

PHP OneSignal Push Notification Send to Specific User

$content = array(
"en" => $message//mesaj burasi
);
$fields = array(
'app_id' => "e3b90484-e534-4a11-9b87-3b9c2fbd413",
'included_segments' =>  array("Active Users", "Inactive Users"),
'data' => array("foo" => "bar"),
'filters' => array(array('field' => 'tag', 'key' => 'userId', 'relation' => '=', 'value' => $userId)),
'contents' => $content
);

$fields = json_encode($fields);
print("\nJSON sent:\n");
print($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 ZjY5MjA3ZGYtYjY2Yy00YjVjJjYjctMzZhMWFiODdmMTEz'));
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);

By using filters parameters stated in line 8, we send notification to only one user with related user id.



PayPal - The safer, easier way to pay online!


Comments About Tutorial


EDUARDO CASTRO DA SILVA
01-11-2017

hello I'm from Brazil How to get the One's Signal's User ID by Php, write to the bank, create a send routine (Php + MySql + Onesignal) ... do you have any idea ??? Congratulations and Thank you.

ANSWER

JOE ABDEL SATER
20-03-2018

Hello, What should i do if i would like send notifications to more than just one user, and the ids of these users are being returned by a query.

ANSWER


Add Comment

Name*
Surname* 
Email* 
Subject* 
What is (12 + 5) :
WARNING

Please fill all text boxes

Message Result

Your comment is saved. After approved, it will be published

An Error Occured

We are sorry, your request cannot be continued try again later

LOGIN REQUESTED

Please login for this operation
Login