Skip to main content
All OneSignal server SDKs are generated from the same OpenAPI specification, so they share a consistent interface regardless of language. Each SDK wraps the OneSignal REST API and provides typed models for requests and responses. Every SDK covers the same set of endpoints: Notifications, Users, Subscriptions, Segments, Templates, Live Activities, Custom Events, API Keys, and Apps.

Available SDKs


Before you begin

Gather these values from your OneSignal dashboard before installing an SDK. See Keys & IDs for where to find each one.
  1. App ID — the unique identifier for your OneSignal app.
  2. REST API Key — required for most endpoints (sending notifications, managing users).
  3. Organization API Key (optional) — only required for organization-level endpoints like creating or listing apps.

Installation

Version numbers below are examples. Check the package registry for each SDK to install the latest version.
npm install @onesignal/node-onesignal

Configuration

Every SDK requires authentication via API keys. Two key types are available:
  • REST API Key — required for most endpoints (sending notifications, managing users, etc.). Found in your app’s Settings > Keys & IDs.
  • Organization API Key — only required for organization-level endpoints like creating or listing apps. Found in Organization Settings.
Store your API keys in environment variables or a secrets manager. Never commit them to source control. The examples below read from ONESIGNAL_REST_API_KEY and ONESIGNAL_ORGANIZATION_API_KEY.
const OneSignal = require('@onesignal/node-onesignal');

const configuration = OneSignal.createConfiguration({
  restApiKey: process.env.ONESIGNAL_REST_API_KEY,
  organizationApiKey: process.env.ONESIGNAL_ORGANIZATION_API_KEY,
});

const client = new OneSignal.DefaultApi(configuration);

Send a push notification

Send push notifications to web and mobile Subscriptions by targeting a segment. Each example wraps the send call in try/catch (or the language equivalent) so failures surface instead of silently swallowing errors.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = { en: 'Hello from OneSignal!' };
notification.headings = { en: 'Push Notification' };
notification.included_segments = ['Subscribed Users'];

try {
  const response = await client.createNotification(notification);
  console.log('Notification ID:', response.id);
} catch (error) {
  console.error('Failed to create notification:', error);
}
The .NET SDK does not normalize newline characters automatically. If your content contains \r\n, normalize it before passing to Contents:
var normalizedContent = yourContent
    .Replace("\\r\\n", "\n")
    .Replace("\\n", "\n")
    .Replace("\r\n", "\n")
    .Replace("\r", "\n");

Send an email

Send emails to Subscriptions with the email channel.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.email_subject = 'Important Update';
notification.email_body = '<h1>Hello!</h1><p>This is an HTML email.</p>';
notification.included_segments = ['Subscribed Users'];
notification.channel_for_external_user_ids = 'email';

try {
  const response = await client.createNotification(notification);
  console.log('Notification ID:', response.id);
} catch (error) {
  console.error('Failed to create notification:', error);
}

Send an SMS

Send SMS text messages to Subscriptions with the sms channel.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = { en: 'Your SMS message content here' };
notification.included_segments = ['Subscribed Users'];
notification.channel_for_external_user_ids = 'sms';
notification.sms_from = '+15551234567';

try {
  const response = await client.createNotification(notification);
  console.log('Notification ID:', response.id);
} catch (error) {
  console.error('Failed to create notification:', error);
}

Common send patterns

Target specific users, target specific devices, or schedule delivery. The JSON field names shown below map identically across every SDK — call the equivalent setter on your Notification object (setIncludeAliases / include_aliases, setSendAfter / send_after, etc.).
Send to specific users by their external_id alias. You must set target_channel when using aliases so OneSignal knows which channel to route the message on.
Keys under include_aliases must match API alias labels exactly (for example, external_id, not externalId).
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = { en: 'Hello from OneSignal!' };
notification.include_aliases = { external_id: ['YOUR_USER_EXTERNAL_ID'] };
notification.target_channel = 'push';

const response = await client.createNotification(notification);
Send to specific subscriptions by their OneSignal-generated subscription ID. Use this when you already know the exact devices or channels you want to reach.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = { en: 'Hello from OneSignal!' };
notification.include_subscription_ids = ['SUBSCRIPTION_ID_1', 'SUBSCRIPTION_ID_2'];

const response = await client.createNotification(notification);
Set send_after to a future timestamp to schedule delivery. Optionally set delayed_option to timezone or last-active to deliver per-subscription at a local time.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = { en: 'Reminder: your event starts soon.' };
notification.included_segments = ['Subscribed Users'];
notification.send_after = 'Thu Sep 24 2026 14:00:00 GMT-0700';

const response = await client.createNotification(notification);

Verify your setup

After calling createNotification, check the response for a non-empty id to confirm the notification was accepted:
Successful response
{
  "id": "b6b326a8-40aa-4204-b430-73cbc0f5d5b6",
  "recipients": 42,
  "external_id": null
}
The API may return HTTP 200 with an empty id when no matching subscribed recipients are found. Always check response.id before assuming the send succeeded, and inspect response.errors for details.
Response with no matching recipients
{
  "id": "",
  "recipients": 0,
  "errors": ["All included players are not subscribed"]
}
If you see an empty id, common causes are:
  • Segment name is misspelled or has the wrong case (segment names are case-sensitive).
  • The external_id or subscription ID does not exist in your app.
  • All targeted subscriptions are unsubscribed.

Common errors

StatusMeaningAction
400Malformed request or invalid fieldCheck field names and payload shape against the REST API reference.
401Missing or invalid API keyVerify the key value and that it matches the app you’re targeting.
403Wrong key scope (e.g. app REST key for an org endpoint)Use the Organization API Key for org-level endpoints.
404App, notification, user, or subscription not foundVerify the ID or alias in the dashboard.
409Conflict — duplicate resourceFor idempotent sends, this typically means the idempotency_key was replayed.
429Rate limit exceededWait for the Retry-After header before retrying; use exponential backoff.
5xxServer errorRetry with exponential backoff.

Full API reference

Each server SDK supports the same set of endpoints — Notifications, Users, Subscriptions, Segments, Templates, Live Activities, Custom Events, API Keys, and Apps. The DefaultApi docs list every method; the models docs describe request and response shapes. Each SDK also ships an AGENTS.md with an integration guide tailored to LLM-assisted coding. For the underlying REST API, see the complete API reference.

FAQ

Which server SDK should I choose?

Use the SDK that matches your backend language. All server SDKs are generated from the same OpenAPI specification and support the same endpoints, so functionality is identical across languages.

What is the difference between the REST API Key and Organization API Key?

The REST API Key is scoped to a single app and is required for most operations like sending notifications and managing users. The Organization API Key is scoped to your organization and is only needed for creating or listing apps. Most integrations only need the REST API Key.

Can I use the REST API directly instead of an SDK?

Yes. The server SDKs are convenience wrappers around the OneSignal REST API. You can call the API directly using any HTTP client with the key authentication scheme (Authorization: key YOUR_REST_API_KEY).

Are these SDKs auto-generated?

Yes. All server SDKs are generated from the OneSignal OpenAPI specification using OpenAPI Generator. This ensures consistent API coverage across all languages.

REST API overview

Endpoints, authentication, rate limits, and request/response formats.

Keys & IDs

Find your App ID, REST API key, and Organization API key.

Transactional messages

Send OTPs, receipts, and time-sensitive alerts via API with personalized data.

Identity verification

Secure your integration with server-generated JWTs to prevent User impersonation.