We are pleased to announce that the OneSignal Typescript/Node SDK is now available. This Typescript client supports developers using OneSignal by facilitating the process of integrating the OneSignal REST API with your backend events, data, and more. This release is part of our ongoing initiative to add server SDKs across various languages and technologies.
What is this library?
OneSignal Typescript/Node API is a faster way to get started using OneSignal REST API that is accessible as a REST service.
This library has been generated using OpenApi Generator project with several modifications and fixes on our side.
Install
# yarn
yarn add @onesignal/node-onesignal
# npm
npm install @onesignal/node-onesignal --save
Usage
const OneSignal = require('@onesignal/node-onesignal');
import * as OneSignal from '@onesignal/node-onesignal';
Creating a client
Configuration
We can configure the client using the createConfiguration
function.
const configuration = OneSignal.createConfiguration(configParams);
Initializing the Client
const client = new OneSignal.DefaultApi(configuration);
Authentication
You can configure auth parameters passing them like this:
const configuration = OneSignal.createConfiguration({
userKey: '<YOUR_USER_KEY_TOKEN>',
appKey: '<YOUR_APP_KEY_TOKEN>',
});
const client = new OneSignal.DefaultApi(configuration);
You can find all the keys you need on the dashboard page of your app:
- to get APP_ID:
Go to https://app.onesignal.com/apps/ page, find your application and open it. You can fin the APP ID in the URL. - to get APP_KEY_TOKEN:
Go tohttps://app.onesignal.com/apps/<YOUR_APP_ID>/settings/keys_and_ids
page.
If you don't have a Rest API Key already generated - please generate a new one by clicking a Generate New API Key button. - to get USER_KEY_TOKEN:
Go to https://app.onesignal.com/profile page and scroll down to the User Auth Key section.
If you don't have an AUTH KEY already generated - please generate a new one by clicking a Generate New User Auth Key button.
Example: Creating a notification
Sends a notification to your users.
const notification = new OneSignal.Notification();
notification.app_id = app.id;
notification.contents = {
en: "Gig'em Ags"
}
// required for Huawei
notification.headings = {
en: "Gig'em Ags"
}
const notification = await client.createNotification(notification);
For more examples and detailed API reference please visit out GitHub repository.
Reference
Visit our REST API Reference documentation for a complete list of our supported endpoints.
Visit our Typescript/node API reference for a list of supported functions and view implementation examples in Typescript.
Share Your Feedback
If you’ve had a chance to use our new Typescript SDK and have any feedback or suggestions you’d like to share, please reach out to us on the GitHub repository or our Discord server.
If you encounter any bugs or technical issues while using our new Typescript SDK, we want to know so we can resolve the issue. If you're having trouble, please be sure to file a report on our GitHub repository.
If you’ve found the plugin helpful, we’d also appreciate it if you left us a review on G2.
Join our Discord Server