OneSignal REST API documentationSee the full OneSignal REST API reference.
When to use programmatic notifications
Use the REST API when a notification is triggered by something that happens in your system instead of manually hitting send. Common use cases:- Order and shipping updates: notify a user when their status changes
- Message alerts: let users know they have a new message waiting
- Account activity: password changes, sign-in attempts, payment confirmations
- Re-engagement: reach users who haven’t opened the app after a number of days
- Personalized reminders: based on a user’s saved preferences or upcoming events
Targeting by user
The most common use case is to send the notification to all devices belonging to a specific user. This requires associating the user with an identifier viamedian.onesignal.login(). See Identifying & targeting users for how to set that up.
User identifiers
Targeting by segment
Segments let you broadcast to large groups of users defined by shared attributes such as data tags, subscription status, location, and more.Targeting by specific device
To target one specific device, for example, the device a user is currently active on, use thesubscription.id. Retrieve this from the oneSignalInfo object in your app and store it in your backend.
subscription.id is linked to the app on the user’s device. It only changes if the app is uninstalled and reinstalled. For most personalized notifications, targeting by external_id is more reliable.
Finding your app ID and API key
- Sign in to your OneSignal dashboard.
- Select your app.
- Go to Settings > Keys & IDs.