Skip to main content
Programmatic notifications are sent in response to events triggered from your server, such as a user’s trial ending soon, or their order being ready for pickup. They’re the backbone of transactional and behavioral messaging, and they’re sent via the OneSignal REST API rather than the dashboard. This guide covers when to use the API, how to target users by different methods, and a working example.
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
For one-off campaigns and broadcasts, sending from the OneSignal dashboard is usually faster.

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 via median.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.
You can include multiple segments and exclude others in the same request. Segments are created and managed in the OneSignal dashboard. See Identifying & targeting users for how to use data tags to build segments programmatically.

Targeting by specific device

To target one specific device, for example, the device a user is currently active on, use the subscription.id. Retrieve this from the oneSignalInfo object in your app and store it in your backend.
The 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

  1. Sign in to your OneSignal dashboard.
  2. Select your app.
  3. Go to Settings > Keys & IDs.
Keep your REST API Key privateYour REST API Key is a server-side secret. Never include it in client-side JavaScript or mobile app code; it authorizes sending notifications on your behalf.

Full example: send to a user by external ID

Here’s a complete request that sends an Order Shipped notification to a user targeted by their external ID. Replace the placeholder values with your own credentials from the OneSignal dashboard (Settings > Keys & IDs).
Key fields:
Last modified on November 7, 2026