Ionic Push: Send PUSH to all users using API

I see in the control panel possibility to send push notification to all users. Is it possible to do the same using API? I tried already to send a request with empty tokens array "tokens": [] however, no notifications were delivered.

If it’s not yet possible to do through the API, can you suggest me the best practice how to store these tokens on backend side in DB? I see that app generates token each time on startup, and I don’t have and don’t want to have registration. So, basically, if user will kill and re-open app 100 times I will save 100 different tokens for his device.
How can I understand that some tokens are already outdated and should be removed from DB?

So far I used the standard code to register device in ionic platform:

    var push = new Ionic.Push({
      "debug": true,
      "pluginConfig": {
        "ios": {
          badge: "false",
          sound: "true"
        }
      },
      "onNotification": function(notification) {
        var payload = notification.payload;
        console.log(notification, payload);
      },
      "onError": function(err) {
        console.log(JSON.stringify(err));
      }
    });

    push.register(function(token) {
      console.log("Device token:",token.token);
      push.saveToken(token);  // persist the token in the Ionic Platform
    });

Still didn’t find a solution without registration. So far had to implement simple subscription with email + hidden deviceToken and save it in DB with Devices.findOrCreate(where: { email: email}, defaults : {device_token : token}) on backend side. In this case, 1 mobile device has only one unique token. However, those who didn’t subscribe to push notifications with their email will never receive them.

Is it possible to see the list of all devices which were registered with push.saveToken(token); in the Ionic Dashboard?

this was annoying for me too but found it here-

{
  "tokens": [""],
  "send_to_all": true,
  "profile":"profile_name_goes_here",
  "notification":{
    "message": "ionicpush send to all."
  }
}
2 Likes

Thank you, @temitope! I have no idea why I didn’t find it anywhere in docs…

i been looking for this “send_to_all” variable for past 8 hour… thanks @temitope. you made my day

Thank you temitope