Issue
i want to send a notification to (Segments) target like ["Active Users"] with parameter "included_segments" but When i call the API using CURL in PHP i get this Error : (Please include a case-sensitive header of Authorization: Basic or Bearer token="" with a valid REST API key.).
however the code is running well when i change target from parameter "included_segments" to "include_player_ids" .. but i want "included_segments" .. please HELP Me!.
- this is my Code : `
function Copts($titlEN,$titlAR,$contEN,$contAR,$icon,$img){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://onesignal.com/api/v1/notifications',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"app_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"included_segments": ["Active Users"],
"contents": {"en": "'.$contEN.'"},
"headings": {"en": "'.$titlEN.'"},
"global_image": "'.$img.'",
"large_icon": "'.$icon.'"
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
)
));
return json_decode(curl_exec($curl),true);
}
`
Solution
The problem was the REST API KEYS are not correct. USER AUTH KEY instead of REST API KEYS found it here :
dashboard -> settings -> keys & ids
See documentation here : https://documentation.onesignal.com/docs/accounts-and-keys
.
Answered By - ertibi Answer Checked By - Marilyn (WPSolving Volunteer)