Send Push Notifications to Individual Users

Updated on 20. December 2023 by Jan Bunk


The features described on this page require a plan that includes push notifications.

The basic concept on how you can send push notifications to individual users of your app is as follows:

In this guide, 'user' always refers to a person that has a user account on your website.
  1. Your user John opens the app.
  2. Your website calls the javascript function getNotificationToken which returns the app instance's push notification token.
  3. Your website stores the token (for example in John's entry in your user database).
  4. When you want to send a notification to John, you call the webtoapp.design API with the token and we will deliver the notification.

Using the Javascript Function

You might want to check out the executeWhenAppReady() function of our app helper script. It ensures that your website doesn't try to interact with the app before it's ready or when your website is loaded using a regular browser (ReferenceError, function is not defined).

When you want to get an app instance's push notification token, simply call the getNotificationToken function.


<script>
    try {
        var token = (await getNotificationToken())["token"];
    }
    catch (e) {
        // Can occur if:
        // - the app couldn't connect to the native code. Should be very unlikely.
        // - the app couldn't get the push notification token, maybe because of connection issues. Should be very unlikely.
        // - push notifications are not included in your current plan
        console.log(e);
    }
</script>
    

Things to keep in mind:

  • The token is a long string, for example:
  • A user's token can change,
    • when the same user uses the app on a different device
    • when the app is uninstalled and reinstalled
    • when the app's data is cleared
    This means that old notification tokens of a user may no longer be valid, so you should regularly store the tokens. In case you want to support the same user using your app on multiple devices, you need to store multiple tokens for each user.
  • Keep the push notification tokens secret.

API Endpoint Reference

Get your app-specific API key from your app dashboard.

Send your API key as a query in the URL and the request body in the JSON format.