Skip to content

Commit

Permalink
Merge pull request #48 from OneSignal/api
Browse files Browse the repository at this point in the history
Dependency Update
kesheshyan authored Jan 10, 2023
2 parents 4fa0399 + fdc41b6 commit bb52e8c
Showing 80 changed files with 4,794 additions and 310 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog
All notable changes to this project will be documented in this file.

## January 2023
### `1.0.0-beta9` - 09/06/2023
- Added User model endpoints
- Limitations
- Recommend using only in development and staging environments for Alpha releases.
- Aliases will be available in a future release
- Outcomes will be available in a future release
- Users are deleted when the last subscription is removed
- Known issues
- User properties may not update when Subscriptions are transferred
- Identity Verification
- We will be introducing JWT in follow up Alpha or Beta release
- Extra disabled subscriptions are created when switching Users in the SDK.

## December 2022
### `1.0.0-beta8` - 11/14/2022
- Added Live Activity endpoints
1,292 changes: 1,139 additions & 153 deletions DefaultApi.md

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -440,6 +440,154 @@ const subscriptionId = '<subscription_id>'; // player id
await api.endLiveActivity('<app_id>', '<activity_id>', subscriptionId);
```

### Subscription types
* iOSPush
* AndroidPush
* FireOSPush
* ChromeExtensionPush
* ChromePush
* WindowsPush
* SafariLegacyPush
* FirefoxPush
* macOSPush
* HuaweiPush
* SafariPush
* Email
* SMS

## Users
### Creating a OneSignal User
```js
const user = new OneSignal.User();

const aliasLabel = '<alias_label>';
const aliasId = '<alias_id>';
const subscriptionToken = '<subscription_token>';

user.identity = {
[aliasLabel]: aliasId,
};

user.subscriptions = [
{
type: "iOSPush",
token: subscriptionToken,
}
];

const createdUser = await api.createUser('<app_id>', user);
assert(createdUser.identity!['onesignal_id'] != null);
```

### Getting a user by `onesignal_id`
```js
const oneisgnalAliasLabel = "onesignal_id";
const onesignalAliasId = createdUser.identity!['onesignal_id'];

const fetchedUser = await api.fetchUser('<app_id>', oneisgnalAliasLabel, onesignalAliasId);
```

### Getting a user by an alias
```js
const fetchedUser = await api.fetchUser('<app_id>', alias_label, alias_id);
```

### Updating a user
```js
const updateUserRequest: UpdateUserRequest = {
properties: {
language: 'fr'
}
};

const updatedUser = await api.updateUser('<app_id>', aliasLabel, aliasId, updateUserRequest);
```

### Deleting a user
```js
await api.deleteUser('<app_id>', aliasLabel, aliasId);
```

## Subscriptions
### Creating a subscription for existing user
```js
const createSubscriptionRequestBody: CreateSubscriptionRequestBody = {
subscription: {
type: "AndroidPush",
token: '<subscription_token>',
}
};

const response = await api.createSubscription('<app_id>', '<alias_label>', '<alias_id>', createSubscriptionRequestBody);
```

### Updating a subscription
```js
const updateSubscriptionRequestBody: UpdateSubscriptionRequestBody = {
subscription: {
type: "iOSPush",
token: '<new-subscription-token>',
}
};

await api.updateSubscription('<app_id>', '<existing_subscription_id>', updateSubscriptionRequestBody);
```

### Deleting a subscription
```js
await api.deleteSubscription('<app_id>', '<subscription_id>');
```

### Transfer subscription ownership
Transfers the subscription from one user to another.
```js
// Setting the user for transfering the subscription to. User is identyfied by an IdentityObject.
const transferSubscriptionRequestBody: TransferSubscriptionRequestBody = {
identity: otherUserIdentityObject
};

const transferResponse = await api.transferSubscription('<app_id>', '<subscription_id>', transferSubscriptionRequestBody);
```

## Aliases
### Fetching aliases for a user
```js
const fetchResponse = await api.fetchAliases('<app_id>', '<subscription_id>');
```

### Fetching user identity
```js
const fetchResponse = await api.fetchUserIdentity('<app_id>', '<alias_label>', '<alias_id>');
```
### Identifying user by alias
```js
const userIdentityRequestBody: UserIdentityRequestBody = {
identity: {
['<new_alias_label>']: '<new_alias_id>'
}
};

const identifyResponse = await api.identifyUserByAlias('<app_id>',
'<existing_alias_label>',
'<existing_alias_id>',
userIdentityRequestBody);
```

### Identifying user by subscription id
```js
const userIdentityRequestBody: UserIdentityRequestBody = {
identity: {
['<new_alias_label>']: '<new_alias_id>'
}
};

const identifyResponse = await api.identifyUserBySubscriptionId('<app_id>', '<existing_subscription_id>', userIdentityRequestBody);
```

### Deleting an alias
```js
await api.deleteAlias('<app_id>', '<alias_label>', '<alias_id>', '<alias_label_to_delete>');
```
## Author

* Website: https://onesignal.com
Loading

0 comments on commit bb52e8c

Please sign in to comment.