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.
- Your user John opens the app.
- Your website calls the javascript function
getNotificationTokenwhich returns the app instance's push notification token. - Your website stores the token (for example in John's entry in your user database).
- When you want to send a notification to John, you call the app-control-panel.com 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) {
switch(e) {
case "Notification token not available yet. Please try again shortly.":
// The device has not finished push notification registration yet. Typically this can happen on iOS
// immediately after starting the app. You can try again after a delay or consider calling the function
// during another point in your app's lifecycle.
break;
default:
// 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);
break;
}
}
</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
- 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.