Documentation

Subscribe to Topics (Optional)


Optionally subscribe the device to one or more topics to target multiple users with a shared interest when sending notifications.

Depending on your app's notification criteria, you may be able to leverage topics to simply the process of sending the same notification to multiple users. If your app only sends personalized notifications, skip this step and simply target individual devices by specifying their tokens.


Simply add the following code to subscribe a registered device to a topic:

// Check if the device is registered
if (Pushy.isRegistered()) {
    // Subscribe the device to a topic
    Pushy.subscribe('news').catch(function (err) {
        // Handle subscription errors
        console.error('Subscribe failed:', err);
    });
}

Note: Make sure to replace news with your own case-sensitive topic name that matches the following regular expression: [a-zA-Z0-9-_.]+. You may also pass in a string array with multiple topics.


You can then notify multiple devices subscribed to a certain topic by specifying the topic name (prefixed with /topics/) as the to parameter in the Send Notifications API.