MCPcopy Index your code
hub / github.com/OneSignal/onesignal-node-api

github.com/OneSignal/onesignal-node-api @v5.10.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v5.10.0 ↗ · + Follow
664 symbols 1,664 edges 86 files 240 documented · 36%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Welcome to @onesignal/node-onesignal

Version Documentation Maintenance

The OneSignal Node client is a server SDK for NodeJS. A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com.

Installation

# npm
npm install @onesignal/node-onesignal

# pnpm
pnpm add @onesignal/node-onesignal

# bun
bun add @onesignal/node-onesignal

# yarn
yarn add @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.

Warning: Store your API keys in environment variables or a secrets manager. Never commit them to source control.

const OneSignal = require('@onesignal/node-onesignal');

const configuration = OneSignal.createConfiguration({
    restApiKey: 'YOUR_REST_API_KEY',
    organizationApiKey: 'YOUR_ORGANIZATION_API_KEY',
});

const client = new OneSignal.DefaultApi(configuration);

Send a push notification

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'];

const response = await client.createNotification(notification);
console.log('Notification ID:', response.id);

Send with idempotent retries

createNotificationWithRetry generates a UUIDv4 idempotency_key when absent (a caller-provided key is respected), retries 429 / 503 / transport errors with the same key (honoring Retry-After, exponential backoff otherwise; maxRetries / baseDelayMs configurable via the options object), fails fast on other errors, and reports via wasReplayed whether the server answered from a previously completed request (Idempotent-Replayed response header). It is a DefaultApi method, so the call mirrors createNotification:

const result = await client.createNotificationWithRetry(notification);
console.log('Notification ID:', result.response.id, 'replayed:', result.wasReplayed);

Send a push notification by External ID

Target specific users with the alias label external_id (snake_case). This is different from the notification-level external_id field, which is only for idempotent requests.

You must set target_channel when sending push (or email/SMS) to alias targets.

const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = { en: 'Hello from OneSignal!' };
notification.headings = { en: 'Push Notification' };
// Keys under include_aliases must match API alias labels exactly (e.g. external_id, not externalId).
notification.include_aliases = { external_id: ['YOUR_USER_EXTERNAL_ID'] };
notification.target_channel = 'push';

const response = await client.createNotification(notification);
if (!response.id) {
  console.error('Notification was not created:', response.errors);
} else {
  console.log('Notification ID:', response.id);
}

The API may return HTTP 200 with an empty id when no matching subscribed recipients are found; always check response.id and response.errors.

Send an email

const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.email_subject = 'Important Update';
notification.email_body = '<h1>Hello!</h1>

This is an HTML email.

';
notification.included_segments = ['Subscribed Users'];
notification.channel_for_external_user_ids = 'email';

const response = await client.createNotification(notification);

Send an SMS

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';

const response = await client.createNotification(notification);

Full API reference

The complete list of API endpoints and their parameters is available in the DefaultApi documentation.

For the underlying REST API, see the OneSignal API reference.

Extension points exported contracts — how you extend this code

SecurityAuthentication (Interface)
(no doc) [4 implementers]
auth/auth.ts
BaseServerConfiguration (Interface)
(no doc) [2 implementers]
servers.ts
Middleware (Interface)
(no doc) [2 implementers]
middleware.ts
ResponseBody (Interface)
(no doc) [2 implementers]
http/http.ts
CreateNotificationWithRetryOptions (Interface)
(no doc)
helpers.ts
Configuration (Interface)
(no doc)
configuration.ts
DefaultApiCancelNotificationRequest (Interface)
(no doc)
types/ObjectParamAPI.ts
TokenProvider (Interface)
(no doc)
auth/auth.ts

Core symbols most depended-on inside this repo

text
called by 240
http/http.ts
parse
called by 240
models/ObjectSerializer.ts
deserialize
called by 239
models/ObjectSerializer.ts
pipe
called by 220
rxjsStub.ts
isCodeInRange
called by 198
util.ts
mergeMap
called by 176
rxjsStub.ts
setHeaderParam
called by 112
http/http.ts
toPromise
called by 90
rxjsStub.ts

Shape

Method 417
Class 172
Interface 56
Function 18
Enum 1

Languages

TypeScript100%

Modules by API surface

apis/DefaultApi.ts92 symbols
types/ObjectParamAPI.ts91 symbols
types/PromiseAPI.ts48 symbols
types/ObservableAPI.ts47 symbols
http/http.ts36 symbols
auth/auth.ts16 symbols
middleware.ts11 symbols
helpers.ts10 symbols
servers.ts9 symbols
rxjsStub.ts9 symbols
models/ObjectSerializer.ts9 symbols
apis/baseapi.ts6 symbols

For agents

$ claude mcp add onesignal-node-api \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact