Amine
Amine

Reputation: 961

How to fix OneSignal push notification returning "All included players are not subscribed"?

I'm trying send notifications into a device in which my app is installed using php, pushing notifications to all users was successful when using 'included_segments' => array('All') , but when i try to use filters i get All included players are not subscribed response error, this is the push notification script i'm using:

push.php

<?PHP
function sendMessage(){
    $content = array(
        "en" => 'Testing Message'
        );

    $fields = array(
        'app_id' => <omitted>,
        'filters' => array(array("field" => "tag", "key" => "etab", "relation" => "=", "value" => "1")),
        'data' => array("foo" => "bar"),
        'large_icon' =>"ic_launcher_round.png",
        '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 <omitted>'));
    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);

    return $response;
}

$response = sendMessage();
$return["allresponses"] = $response;
$return = json_encode( $return);
print("\n\nJSON received:\n");
print($return);
print("\n");
?>

Output

JSON sent: {"app_id":<omitted>,"filters":[{"field":"tag","key":"etab","relation":"=","value":"1"}],"data":{"foo":"bar"},"large_icon":"ic_launcher_round.png","contents":{"en":"Testing Message"}} JSON received: {"allresponses":"{\"id\":\"\",\"recipients\":0,\"errors\":[\"All included players are not subscribed\"]}"}

I checked the available tags in my Android app and the tag is successfully implemented and fine.

Upvotes: 0

Views: 4957

Answers (1)

Rodrigo Gomez-Palacio
Rodrigo Gomez-Palacio

Reputation: 904

The "All included players are not subscribed" message could mean any of the following.

  1. Ensure you have set the correct app_id.
  2. You have no subscribed users.
  3. You haven't setup a platform for your devices on the App Settings page on OneSignal's dashboard.
  4. There are no users in the filter.

Upvotes: 2

Related Questions