Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
onesignal-node
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Schedules
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Cedar Studios
onesignal-node
Commits
907fb355
Commit
907fb355
authored
Jul 29, 2018
by
zeynel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README for new endpoints
parent
74f788e4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
31 deletions
+91
-31
README.md
README.md
+91
-31
No files found.
README.md
View file @
907fb355
# onesignal-node
A Node.js client library for
[
OneSignal
](
https://onesignal.com/
)
API.
...
...
@@ -7,19 +8,22 @@ A Node.js client library for [OneSignal](https://onesignal.com/) API.
*
[
Installation
](
#installation
)
*
[
Usage
](
*usage
)
*
[
Creating a service client
](
#creating-a-client
)
*
[
Sending a push notification
](
#sending-push-notifications
)
*
[
Cancelling a push notification
](
#cancelling-a-push-notification
)
*
[
Viewing push notifications
](
#viewing-push-notifications
)
*
[
Viewing a push notification
](
#viewing-a-push-notification
)
*
[
Listing apps
](
#viewing-apps
)
*
[
Creating an app
](
#creating-an-app
)
*
[
Updating an app
](
#updating-an-app
)
*
[
Listing devices
](
#viewing-devices
)
*
[
Viewing a device
](
#viewing-a-device
)
*
[
Adding a device
](
#adding-a-device
)
*
[
Editing a device
](
#editing-a-device
)
*
[
Send a push notification
](
#send-push-notifications
)
*
[
Cancel a push notification
](
#cancel-a-push-notification
)
*
[
View push notifications
](
#view-push-notifications
)
*
[
View a push notification
](
#view-a-push-notification
)
*
[
View apps
](
#view-apps
)
*
[
Create an app
](
#create-an-app
)
*
[
Update an app
](
#update-an-app
)
*
[
View devices
](
#view-devices
)
*
[
View a device
](
#view-a-device
)
*
[
Add a device
](
#add-a-device
)
*
[
Edit a device
](
#edit-a-device
)
*
[
New session
](
#new-session
)
*
[
New purchase
](
#new-purchase
)
*
[
Increment Session Length
](
#increment-session-length
)
*
[
CSV Export
](
#csv-export
)
*
[
Open
ing track
](
#opening-track
)
*
[
Open
track
](
#open-track
)
*
[
Tests
](
#tests
)
## Installation
...
...
@@ -36,7 +40,7 @@ var OneSignal = require('onesignal-node');
You can create a OneSignal Client as shown below. It takes a JSON object as parameter which
contains your OneSignal API credentials.
You can find your userAuthKey and REST API Key (appAuthKey) on OneSignal
`Account & API Keys`
page.
```
js
```
js
// create a new Client for a single app
var
myClient
=
new
OneSignal
.
Client
({
userAuthKey
:
'XXXXXX'
,
...
...
@@ -46,7 +50,7 @@ var myClient = new OneSignal.Client({
```
You can also create a Client for multiple Apps
```
js
```
js
// create a Client for a multiple apps
var
myClient
=
new
OneSignal
.
Client
({
userAuthKey
:
'XXXXXX'
,
...
...
@@ -54,7 +58,7 @@ var myClient = new OneSignal.Client({
});
```
You can always create a Client with no credential and set them later:
```
js
```
js
// create a Client for a multiple apps
var
myClient
=
new
OneSignal
.
Client
({});
myClient
.
userAuthKey
=
'XXXXXX'
;
...
...
@@ -107,7 +111,7 @@ firstNotification.postBody["data"] = {"abc": "123", "foo": "bar"};
firstNotification
.
postBody
[
"headings"
]
=
{
"en"
:
"English Title"
,
"es"
:
"Spanish Title"
};
```
### Send
ing Push Notifications
### Send
Push Notifications
Sending a notification using Segments:
```
js
var
OneSignal
=
require
(
'onesignal-node'
);
...
...
@@ -227,7 +231,7 @@ myClient.userAuthKey = 'XXXXXX';
myClient
.
apps
=
[
'id1'
,
'id2'
];
```
### Cancel
ling a push notification
### Cancel
a push notification
You can cancel a notification simply by calling
`.cancel(notificationId, callback)`
method
```
js
// this will cancel the notification for current app (myClient.app)
...
...
@@ -238,7 +242,7 @@ myClient.cancelNotification('notificationId', function (err, httpResponse, data)
})
```
### View
ing push notifications
### View
push notifications
To view all push notifications for an app:
```
js
...
...
@@ -254,7 +258,7 @@ myClient.viewNotifications('limit=30', function (err, httpResponse, data) {
});
```
### View
ing a push notification
### View
a push notification
```
js
var
myClient
=
new
OneSignal
.
Client
({
...
...
@@ -269,7 +273,7 @@ myClient.viewNotification('notificationId', function (err, httpResponse, data) {
});
```
### View
ing apps
### View
apps
```
js
myClient
.
viewApps
(
function
(
err
,
httpResponse
,
data
)
{
console
.
log
(
data
[
0
].
name
);
// print the name of the app
...
...
@@ -282,7 +286,7 @@ myClient.viewApp('appId', function (err, httpResponse, data) {
});
```
### Creat
ing an app
### Creat
e an app
```
js
var
OneSignal
=
require
(
'onesignal-node'
);
...
...
@@ -303,7 +307,7 @@ myClient.createApp(appBody, function (err, httpResponse, data) {
});
```
### Updat
ing an app
### Updat
e an app
```
js
var
OneSignal
=
require
(
'onesignal-node'
);
...
...
@@ -322,7 +326,7 @@ myClient.updateApp(appBody, function (err, httpResponse, data) {
});
```
### View
ing devices
### View
devices
You can view devices for an app:
```
js
var
myClient
=
new
OneSignal
.
Client
({
...
...
@@ -335,8 +339,8 @@ myClient.viewDevices('limit=100&offset=0', function (err, httpResponse, data) {
});
```
### View
ing a device
```
js
### View
a device
```
js
var
myClient
=
new
OneSignal
.
Client
({
app
:
{
appAuthKey
:
'XXXXX'
,
appId
:
'XXXXX'
}
});
...
...
@@ -346,8 +350,8 @@ myClient.viewDevice('deviceId', function (err, httpResponse, data) {
});
```
### Add
ing a device
```
js
### Add
a device
```
js
var
myClient
=
new
OneSignal
.
Client
({
userAuthKey
:
'XXXXXX'
,
...
...
@@ -365,8 +369,8 @@ myClient.addDevice(deviceBody, function (err, httpResponse, data) {
});
```
### Edit
ing a device
```
js
### Edit
a device
```
js
var
myClient
=
new
OneSignal
.
Client
({
userAuthKey
:
'XXXXXX'
,
app
:
{
appAuthKey
:
'XXXXX'
,
appId
:
'XXXXX'
}
...
...
@@ -382,8 +386,64 @@ myClient.editDevice('deviceId', deviceBody, function (err, httpResponse, data) {
...
});
```
### New Session
```
js
var
myClient
=
new
OneSignal
.
Client
({
userAuthKey
:
'XXXXXX'
,
app
:
{
appAuthKey
:
'XXXXX'
,
appId
:
'XXXXX'
}
});
var
postBody
=
{
language
:
'es'
,
game_version
:
'1.0'
,
timezone
:
-
28800
};
myClient
.
newSession
(
'playerId'
,
postBody
,
function
(
err
,
httpResponse
,
data
)
{
...
});
```
### New Purchase
```
js
var
myClient
=
new
OneSignal
.
Client
({
userAuthKey
:
'XXXXXX'
,
app
:
{
appAuthKey
:
'XXXXX'
,
appId
:
'XXXXX'
}
});
var
postBody
=
{
purchases
:
[{
sku
:
'SKU123'
,
iso
:
'USD'
,
amount
:
0.99
}]
};
myClient
.
newPurchase
(
'playerId'
,
postBody
,
function
(
err
,
httpResponse
,
data
)
{
...
});
```
### Increment Session Length
```
js
var
myClient
=
new
OneSignal
.
Client
({
userAuthKey
:
'XXXXXX'
,
app
:
{
appAuthKey
:
'XXXXX'
,
appId
:
'XXXXX'
}
});
var
postBody
=
{
state
:
'ping'
,
active_time
:
60
};
myClient
.
incrementSessionLength
(
'playerId'
,
postBody
,
function
(
err
,
httpResponse
,
data
)
{
...
});
```
### CSV Export
```
js
```
js
var
myClient
=
new
OneSignal
.
Client
({
userAuthKey
:
'XXXXXX'
,
app
:
{
appAuthKey
:
'XXXXX'
,
appId
:
'XXXXX'
}
...
...
@@ -394,7 +454,7 @@ myClient.csvExport({ extra_fields: ['location'] }, function (err, httpResponse,
});
```
### Open
ing track
### Open
track
```
js
var
myClient
=
new
OneSignal
.
Client
({
userAuthKey
:
'XXXXXX'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment