@@ -440,6 +440,154 @@ const subscriptionId = '<subscription_id>'; // player id
440
440
await api .endLiveActivity (' <app_id>' , ' <activity_id>' , subscriptionId);
441
441
```
442
442
443
+ ### Subscription types
444
+ * iOSPush
445
+ * AndroidPush
446
+ * FireOSPush
447
+ * ChromeExtensionPush
448
+ * ChromePush
449
+ * WindowsPush
450
+ * SafariLegacyPush
451
+ * FirefoxPush
452
+ * macOSPush
453
+ * HuaweiPush
454
+ * SafariPush
455
+ * Email
456
+ * SMS
457
+
458
+ ## Users
459
+ ### Creating a OneSignal User
460
+ ``` js
461
+ const user = new OneSignal.User ();
462
+
463
+ const aliasLabel = ' <alias_label>' ;
464
+ const aliasId = ' <alias_id>' ;
465
+ const subscriptionToken = ' <subscription_token>' ;
466
+
467
+ user .identity = {
468
+ [aliasLabel]: aliasId,
469
+ };
470
+
471
+ user .subscriptions = [
472
+ {
473
+ type: " iOSPush" ,
474
+ token: subscriptionToken,
475
+ }
476
+ ];
477
+
478
+ const createdUser = await api .createUser (' <app_id>' , user);
479
+ assert (createdUser .identity ! [' onesignal_id' ] != null );
480
+ ```
481
+
482
+ ### Getting a user by ` onesignal_id `
483
+ ``` js
484
+ const oneisgnalAliasLabel = " onesignal_id" ;
485
+ const onesignalAliasId = createdUser .identity ! [' onesignal_id' ];
486
+
487
+ const fetchedUser = await api .fetchUser (' <app_id>' , oneisgnalAliasLabel, onesignalAliasId);
488
+ ```
489
+
490
+ ### Getting a user by an alias
491
+ ``` js
492
+ const fetchedUser = await api .fetchUser (' <app_id>' , alias_label, alias_id);
493
+ ```
494
+
495
+ ### Updating a user
496
+ ``` js
497
+ const updateUserRequest: UpdateUserRequest = {
498
+ properties: {
499
+ language: ' fr'
500
+ }
501
+ };
502
+
503
+ const updatedUser = await api .updateUser (' <app_id>' , aliasLabel, aliasId, updateUserRequest);
504
+ ```
505
+
506
+ ### Deleting a user
507
+ ``` js
508
+ await api .deleteUser (' <app_id>' , aliasLabel, aliasId);
509
+ ```
510
+
511
+ ## Subscriptions
512
+ ### Creating a subscription for existing user
513
+ ``` js
514
+ const createSubscriptionRequestBody: CreateSubscriptionRequestBody = {
515
+ subscription: {
516
+ type: " AndroidPush" ,
517
+ token: ' <subscription_token>' ,
518
+ }
519
+ };
520
+
521
+ const response = await api .createSubscription (' <app_id>' , ' <alias_label>' , ' <alias_id>' , createSubscriptionRequestBody);
522
+ ```
523
+
524
+ ### Updating a subscription
525
+ ``` js
526
+ const updateSubscriptionRequestBody: UpdateSubscriptionRequestBody = {
527
+ subscription: {
528
+ type: " iOSPush" ,
529
+ token: ' <new-subscription-token>' ,
530
+ }
531
+ };
532
+
533
+ await api .updateSubscription (' <app_id>' , ' <existing_subscription_id>' , updateSubscriptionRequestBody);
534
+ ```
535
+
536
+ ### Deleting a subscription
537
+ ``` js
538
+ await api .deleteSubscription (' <app_id>' , ' <subscription_id>' );
539
+ ```
540
+
541
+ ### Transfer subscription ownership
542
+ Transfers the subscription from one user to another.
543
+ ``` js
544
+ // Setting the user for transfering the subscription to. User is identyfied by an IdentityObject.
545
+ const transferSubscriptionRequestBody: TransferSubscriptionRequestBody = {
546
+ identity: otherUserIdentityObject
547
+ };
548
+
549
+ const transferResponse = await api .transferSubscription (' <app_id>' , ' <subscription_id>' , transferSubscriptionRequestBody);
550
+ ```
551
+
552
+ ## Aliases
553
+ ### Fetching aliases for a user
554
+ ``` js
555
+ const fetchResponse = await api .fetchAliases (' <app_id>' , ' <subscription_id>' );
556
+ ```
557
+
558
+ ### Fetching user identity
559
+ ``` js
560
+ const fetchResponse = await api .fetchUserIdentity (' <app_id>' , ' <alias_label>' , ' <alias_id>' );
561
+ ```
562
+ ### Identifying user by alias
563
+ ``` js
564
+ const userIdentityRequestBody: UserIdentityRequestBody = {
565
+ identity: {
566
+ [' <new_alias_label>' ]: ' <new_alias_id>'
567
+ }
568
+ };
569
+
570
+ const identifyResponse = await api .identifyUserByAlias (' <app_id>' ,
571
+ ' <existing_alias_label>' ,
572
+ ' <existing_alias_id>' ,
573
+ userIdentityRequestBody);
574
+ ```
575
+
576
+ ### Identifying user by subscription id
577
+ ``` js
578
+ const userIdentityRequestBody: UserIdentityRequestBody = {
579
+ identity: {
580
+ [' <new_alias_label>' ]: ' <new_alias_id>'
581
+ }
582
+ };
583
+
584
+ const identifyResponse = await api .identifyUserBySubscriptionId (' <app_id>' , ' <existing_subscription_id>' , userIdentityRequestBody);
585
+ ```
586
+
587
+ ### Deleting an alias
588
+ ``` js
589
+ await api .deleteAlias (' <app_id>' , ' <alias_label>' , ' <alias_id>' , ' <alias_label_to_delete>' );
590
+ ```
443
591
## Author
444
592
445
593
* Website: https://onesignal.com
0 commit comments