Skip to content

Commit 98b034c

Browse files
committed
Update README
1 parent 5624250 commit 98b034c

File tree

1 file changed

+80
-29
lines changed

1 file changed

+80
-29
lines changed

README.md

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
### 🏠 [Homepage](https://github.com/OneSignal/node-onesignal#readme)
2020
### 🖤 [npm](https://www.npmjs.com/package/@onesignal/node-onesignal)
2121

22-
## 🚧 In Beta 🚧
23-
## Overview
24-
This is a Node.js wrapper library over OneSignal REST API. You can create notifications, view apps, edit a device and all other actions you can take on OneSignal REST API. Includes Typescript support.
22+
# Node Client SDK
23+
The OneSignal Node client is a server OneSignal SDK for NodeJS. Integrate OneSignal with your backend events, data, and more.
24+
2525

2626
# Install
2727

2828
```sh
29-
// yarn
29+
# yarn
3030
yarn add @onesignal/node-onesignal
3131

32-
// npm
32+
# npm
3333
npm install @onesignal/node-onesignal --save
3434
```
3535

@@ -48,7 +48,6 @@ We can configure the client using the `createConfiguration` function. You can fi
4848
```js
4949
const configuration = OneSignal.createConfiguration(configParams);
5050
```
51-
The returned `configuration` object is what is passed to the `DefaultApi` constructor to initialize the client.
5251

5352
### Initializing the Client
5453
```js
@@ -121,14 +120,37 @@ client = new OneSignal.DefaultApi(configuration);
121120

122121
---
123122
## API Reference
124-
To understand this API, know that requests that change state will follow the following format:
125-
1. create or get an object
126-
2. make changes to that object
127-
3. pass the object to the request function to make the changes.
128-
129-
Examples of important OneSignal objects include `App`, `Notification`, `Player`, and `Segment`.
130123

131-
For example, see the section below on creating an app. First an app object is created via the instantiation of the `App` class. Then, the app instance is modified directly. Finally, we use the `client` to create the app via a remote request.
124+
> To make stateful changes requests should take on the following pattern:
125+
> 1. create or get an object
126+
> 2. make changes to that object
127+
> 3. pass the object to the request function to make the changes
128+
>
129+
> Examples of important OneSignal objects include `App`, `Notification`, `Player`, and `Segment`.
130+
>
131+
> For example, see the section below on creating an app. First an app object is created via the instantiation of the `App` class. Then, the app instance is modified directly. Finally, we use the `client` to create the app via a remote request.
132+
133+
| Function | HTTP Request | Description |
134+
|------------------------------------------------------------------------------------------------------------------------|------------------------------------------------|-----------------------------------------------------|
135+
| [CancelNotification](#canceling-a-notification) | Delete /notifications/{notification_id} | Stop a scheduled or currently outgoing notification |
136+
| [CreateApp](#creating-an-app) | Post /apps | Create an app |
137+
| [CreateNotification](#creating-a-notification) | Post /notifications | Create notification |
138+
| [CreatePlayer](#creating-a-player) | Post /players | Add a device |
139+
| [CreateSegments](#creating-a-segment) | Post /apps/{app_id}/segments | Create Segments |
140+
| [DeletePlayer](#deleting-a-player) | Delete /players/{player_id} | Delete a user record |
141+
| [DeleteSegments](#deleting-a-segment) | Delete /apps/{app_id}/segments/{segment_id} | Delete Segments |
142+
| [ExportPlayers](#exporting-a-player) | Post /players/csv_export?app_id={app_id} | CSV export |
143+
| [GetApp](#getting-an-app) | Get /apps/{app_id} | View an app |
144+
| [GetApps](#getting-multiple-apps) | Get /apps | View apps |
145+
| [GetNotification](#getting-a-notification) | Get /notifications/{notification_id} | View notification |
146+
| [GetNotificationHistory](#getting-notification-history) | Post /notifications/{notification_id}/history | Notification History |
147+
| [GetNotifications](#getting-a-notification) | Get /notifications | View notifications |
148+
| [GetOutcomes](#getting-outcomes) | Get /apps/{app_id}/outcomes | View Outcomes |
149+
| [GetPlayer](#getting-a-player) | Get /players/{player_id} | View device |
150+
| [GetPlayers](#getting-players) | Get /players | View devices |
151+
| [UpdateApp](#getting-an-app) | Put /apps/{app_id} | Update an app |
152+
| [UpdatePlayer](#updating-a-player) | Put /players/{player_id} | Edit device |
153+
| [UpdatePlayerTags](#updating-player-tags) | Put /apps/{app_id}/users/{external_user_id} | Edit tags with external user id |
132154

133155
### Creating an app
134156
Creates a new OneSignal app.
@@ -150,15 +172,23 @@ View the details of a single OneSignal app.
150172

151173
**Example**
152174
```js
153-
client.getApp('<app id>');
175+
await client.getApp('<app id>');
176+
```
177+
178+
### Getting multiple apps
179+
View apps.
180+
181+
**Example**
182+
```js
183+
await client.getApps();
154184
```
155185

156186
### Updating an app
157187
Updates the name or configuration settings of an existing OneSignal app.
158188

159189
**Example**
160190
```js
161-
client.updateApp('<app id>', app);
191+
await client.updateApp('<app id>', app);
162192
```
163193

164194
### Creating a notification
@@ -177,15 +207,25 @@ notification.contents = {
177207
notification.headings = {
178208
en: "Gig'em Ags"
179209
}
180-
client.createNotification(notification);
210+
await client.createNotification(notification);
211+
```
212+
213+
### Canceling a notification
214+
Stop a scheduled or currently outgoing notification.
215+
216+
**Example**
217+
218+
```js
219+
await client.cancelNotification('<app id>', '<notification id>');
181220
```
182221

222+
183223
### Getting a notification
184224
View the details of a single notification and outcomes associated with it.
185225

186226
**Example**
187227
```js
188-
client.getNotification('<app id>', '<notification id>');
228+
await client.getNotification('<app id>', '<notification id>');
189229
```
190230

191231
### Getting notifications
@@ -201,7 +241,7 @@ View the details of multiple notifications.
201241

202242
**Example**
203243
```js
204-
client.getNotifications('<app id>', '50', 0, 1);
244+
await client.getNotifications('<app id>', '50', 0, 1);
205245
```
206246

207247
### Getting notification history
@@ -210,7 +250,7 @@ This method will return all devices that were sent the given `notification_id` o
210250

211251
**Example**
212252
```js
213-
client.getNotificationHistory('<notification id>');
253+
await client.getNotificationHistory('<notification id>');
214254
```
215255

216256
### Creating a segment
@@ -225,7 +265,7 @@ segment.filters = [
225265
{ field: 'tag', key: 'my_tag', relation: 'exists' }
226266
]
227267

228-
client.createSegments(app.id, segment)
268+
await client.createSegments(app.id, segment)
229269
```
230270

231271
### Deleting a segment
@@ -235,15 +275,27 @@ The `segment_id` can be found in the URL of the segment when viewing it in the d
235275

236276
**Example**
237277
```js
238-
client.deleteSegments('<app id>', '<segment id>');
278+
await client.deleteSegments('<app id>', '<segment id>');
279+
```
280+
281+
### Creating a player
282+
Add a device.
283+
284+
**Example**
285+
```js
286+
const player = new OneSignal.Player();
287+
player.device_type = 1;
288+
player.app_id = app_id;
289+
player.identifier = '<identifier>';
290+
await client.createPlayer(player);
239291
```
240292

241293
### Getting a player
242294
View the details of an existing device in one of your OneSignal apps. The email a th hash is **only required if you have enabled Identity Verification and `device_type` is email**.
243295

244296
**Example**
245297
```js
246-
client.getPlayer('<app id>', '<player id>', '<email auth hash>');
298+
await client.getPlayer('<app id>', '<player id>', '<email auth hash>');
247299
```
248300

249301
### Getting players
@@ -258,7 +310,7 @@ View the details of multiple devices in one of your OneSignal apps. Unavailable
258310

259311
**Example**
260312
```js
261-
client.getPlayers('<app id>', '300', 0);
313+
await client.getPlayers('<app id>', '300', 0);
262314
```
263315

264316
### Exporting a player
@@ -268,7 +320,7 @@ See [full CSV Export Reference](https://documentation.onesignal.com/reference/cs
268320

269321
**Example**
270322
```js
271-
client.exportPlayer('<app id>', {
323+
await client.exportPlayer('<app id>', {
272324
extra_fields: ['location', 'external_user_id'],
273325
last_active_since: 1469392779,
274326
segment_name: "Subscribed Users"
@@ -281,7 +333,7 @@ Update an existing device in one of your OneSignal apps.
281333

282334
**Example**
283335
```js
284-
client.updatePlayer('<player id>', player);
336+
await client.updatePlayer('<player id>', player);
285337
```
286338

287339
### Updating player tags
@@ -310,11 +362,11 @@ For example, if I wanted to delete two existing tags rank and category while sim
310362
```
311363

312364
### Deleting a player
313-
Delets a user record.
365+
Deletes a user record.
314366

315367
**Example**
316368
```js
317-
client.deletePlayer(app.id, '<player id>')
369+
await client.deletePlayer(app.id, '<player id>')
318370
```
319371

320372
### Getting outcomes
@@ -335,10 +387,9 @@ Outcome Data Limitations Outcomes are only accessible for around 30 days before
335387

336388
**Example**
337389
```js
338-
client.getOutcomes(app.id, 'os__click.count,os_session_duration.count,my_outcome.sum');
390+
await client.getOutcomes(app.id, 'os__click.count,os_session_duration.count,my_outcome.sum');
339391
```
340392

341-
342393
## Author
343394

344395
* Website: https://onesignal.com

0 commit comments

Comments
 (0)