npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-opensignal-api

v0.0.3

Published

OneSignal API client for node.js

Downloads

3,660

Readme

OneSignal API client for node.js

OneSignal's unofficial node.js client library for using OneSignal Rest API.

Alpha

This library is in Alpha. We will make an effort to support the library, but we reserve the right to make incompatible changes when necessary.

Supported APIs

The full list of supported APIs can be found here. The API endpoints are automatically generated, so if the API is not in the list, it is currently not supported by this API client library.

Questions/problems?

Installation

This library is distributed on npm. In order to add it as a dependency, run the following command:

$ npm install node-opensignal-api --save

Usage

Example: View all apps you have on onesignal:

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var userAuthKey = 'YOUR_USER_AUTH_KEY';
onesignal_client.apps.viewall(userAuthKey, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

Apis

Apps

View all

Server REST API get/apps (View Apps) View the details of all of your current OneSignal apps

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var userAuthKey = 'YOUR_USER_AUTH_KEY';
onesignal_client.apps.viewall(userAuthKey, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

View an app

Server REST API get/apps/:id (View an app) View the details of a single OneSignal app

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var userAuthKey = 'YOUR_USER_AUTH_KEY';
var app_id = 'YOUR_APP_ID'
onesignal_client.apps.view(userAuthKey, app_id, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

Create an app

Server REST API post/apps (Create an app) Create a new OneSignal app

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var userAuthKey = 'YOUR_USER_AUTH_KEY';
var apns_env,
	apns_p2,
	apns_p2_password,
	gcm_key,
	chrome_key,
	safari_apns_p2,
	safari_apns_p12_password,
	site_name,
	safari_site_origin;
onesignal_client.apps.create(userAuthKey, apns_env, apns_p12, apns_p12_password, gcm_key, chrome_key, safari_apns_p12, safari_apns_p12_password, site_name, safari_site_origin, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

Edit an app

Server REST API put/apps/:id (Update an app)

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var userAuthKey = 'YOUR_USER_AUTH_KEY';
var app_id = 'YOUR_APP_ID'
var name,
	apns_env,
	apns_p2,
	gcm_key;
onesignal_client.apps.create(userAuthKey, app_id, name, apns_p12, apns_env, gcm_key, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

Players

View all

Server REST API get/players (View devices)

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var appAuthKey = 'YOUR_APP_AUTH_KEY';
var params = {
	app_id: 'YOUR_APP_ID'	
};
onesignal_client.players.viewall(appAuthKey, params, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

View a player

Server REST API get/players/:id (View device)

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

onesignal_client.players.view(player_id, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

Create a player

Server REST API post/players (Add a device)

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var params = {
	app_id: 'YOUR_APP_ID',
	device_type: 'ONESIGNAL_DEVICE_TYPE'
};
onesignal_client.players.create(params, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

Edit a player

Server REST API put/players/:id (Edit device) Edit an existing device in OneSignal.

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var player_id = 'YOUR_ONESIGNAL_PLAYER_ID';
var params = {};
onesignal_client.players.edit(player_id, params, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

On Session

Server REST API post/players/:id/on_session Call on new device session in your app

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var player_id = 'YOUR_ONESIGNAL_PLAYER_ID';
var params = {};
onesignal_client.players.on_session(player_id, params, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

On Purchase

Server REST API post/players/:id/on_purchase Track a new purchase

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var player_id = 'YOUR_ONESIGNAL_PLAYER_ID';
var params = {
	purchases: [{
		sku: 'SKU',
		amount: '10.00',
		'iso': 'EUR'
	}]
};
onesignal_client.players.on_purchase(player_id, params, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

On Focus

Server REST API post/players/:id/on_focus Increment the device's total session length

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var player_id = 'YOUR_ONESIGNAL_PLAYER_ID';
var params = {
	state: 'ping',
	active_time: 60
};
onesignal_client.players.on_focus(player_id, params, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

CSV Export

Server REST API post/players/csv_export

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var appAuthKey = 'YOUR_APP_AUTH_KEY';
var app_id = 'YOUR_APP_ID';

onesignal_client.players.csv_export(appAuthKey, app_id, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

Notifications

View all

Server REST API get/notifications (View notifications)

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var appAuthKey = 'YOUR_APP_AUTH_KEY';
var app_id = 'YOUR_APP_ID';
var limit = 50;
var offset = 0;
onesignal_client.notifications.viewall(appAuthKey, app_id, limit, offset, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

View a notification

Server REST API get/notifications/:id (View notification) View the details of a notification

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var appAuthKey = 'YOUR_APP_AUTH_KEY';
var notification_id = 'YOUR_ONESIGNAL_NOTIFICATION_ID';
var app_id = 'YOUR_APP_ID';
onesignal_client.notifications.view(appAuthKey, notification_id, app_id, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

Track a notification

Server REST API put/notifications/:id (Track open)

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var notification_id = 'YOUR_ONESIGNAL_NOTIFICATION_ID';
var app_id = 'YOUR_APP_ID';
var opened = true;
onesignal_client.notifications.track(notification_id, app_id, opened, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

Create a notification

Server REST API post/notifications (Create Notification)

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var restApiKey = 'YOUR_APP_REST_API_KEY';
var params = {
	app_id: 'YOUR_APP_ID',
	contents: {
		'en': 'Notification body',
		'es': 'Cuerpo de la notificación'
	},
	tags: [{ "key": "custom_tag", "relation": "=", "value": "custom_value"}]
};
onesignal_client.notifications.create(restApiKey, params, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

Delete a notification

Server REST API delete/notifications/:id (Cancel notification) Stop a scheduled or currently outgoing notification.

var onesignal = require('node-opensignal-api');
var onesignal_client = onesignal.createClient();

var appAuthKey = 'YOUR_APP_AUTH_KEY';
var notification_id = 'YOUR_ONESIGNAL_NOTIFICATION_ID';
var app_id = 'YOUR_APP_ID';
onesignal_client.notifications.delete(appAuthKey, notification_id, app_id, function (err, response) {
	if (err) {
    	console.log('Encountered error', err);
  	} else {
    	console.log(response);
  	}
});

License

This library is licensed under MIT. Full license text is available in LICENSE.

Contributing

See CONTRIBUTING.