OneSignal's unofficial node.js client library for using OneSignal Rest API.
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.
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.
- If you've found an bug/issue, please file it on GitHub.
This library is distributed on npm
. In order to add it as a dependency,
run the following command:
$ npm install node-opensignal-api --save
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
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);
}
});
This library is licensed under MIT. Full license text is available in LICENSE.
See CONTRIBUTING.