Register Devices

Devices need to be uniquely identified to receive push notifications.

Every device is assigned a unique token that you can use to push it at any given time. Once the device has been assigned a token, it should be stored in your application's backend database. When you're ready to push the device, your backend server will send its token to our REST API, and we'll deliver the push notification to the corresponding device.

Device Registration

Add the following code to register the device for push notifications, making sure to populate the appId variable with your Pushy App ID (Pushy Dashboard -> Click your app -> App Settings -> App ID):

// Register device for push notifications
Pushy.register({ appId: 'your-app-id' }).then(function (deviceToken) {
    // Print device token to console
    console.log('Pushy device token: ' + deviceToken);

    // Send the token to your backend server via an HTTP GET request
    //fetch('https://your.api.hostname/register/device?token=' + deviceToken);

    // Succeeded, optionally do something to alert the user
}).catch(function (err) {
    // Handle registration errors

Note: Registration will fail if the user declines the Web Push permission dialog, in which case notification preferences for your hostname must be cleared in the browser settings for the dialog to be displayed again:

  • Firefox: Enter about:preferences#content in the address bar
  • Chrome: Enter chrome://settings/content/notifications in the address bar