How to send push notifications using OneSignal

In this guide we'll walk through how to configure a OneSignal provider in Knock to send push notifications. This guide assumes that you've already created a OneSignal channel in the Knock dashboard.

Your OneSignal channel expects that you are using Knock to author Push notification templates. Those templates are then passed to OneSignal as content.

How to configure OneSignal Push with Knock

💡
Note: this guide assumes that you have already setup OneSignal with push certificates and everything needed in order to start sending push notifications. You should also have already implemented the OneSignal mobile SDK within your application.

To set up OneSignal Push with Knock you will need:

  • Your OneSignal App ID
  • Your OneSignal API Key for sending notifications
  • To select a mode of operation between using external_ids (recommended) or player_ids (deprecated by OneSignal).

Using OneSignal Push with Knock

If you’re using an external id to reference your OneSignal users within Knock, you do not need to supply any additional data to initiate a request. We will automatically pass your Knock user id to OneSignal as the external_id.

Using player_id

When using player_ids you will need to store the player_id for a user within Knock as ChannelData for the OneSignal Push channel. This ensures that Knock has the correct value to pass to send a notification to a recipient when a workflow is triggered.

You can retrieve the player_id from OneSignal once a user has been registered, either by using the OneSignal mobile SDK, or by using a Webhook from OneSignal.

Data passed to OneSignal

When sending a push notification to OneSignal, we will automatically pass the following into the attachments data:

PropertyTypeDescription
knock_message_id*stringThe message ID of the corresponding Knock message
data *stringAny key/value data passed through in your trigger call

Silent/background notifications

When selecting to send as a silent/background notification, Knock will passthrough the content_available=true option to OneSignal. You can enable this per push notification template by clicking "Manage template settings" in the header of the template editor.

Channel data requirements

When your OneSignal push channel is configured to use player_ids you must supply ChannelData per-recipient that contains one or more player_ids for a user.

Frequently asked questions

No, you can currently only use one or the other.