Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
298 changes: 68 additions & 230 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ OneSignal

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

For more information, please visit [https://onesignal.com](https://onesignal.com)

*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)*


## Requirements

Building the API client library requires:
Expand All @@ -18,261 +13,104 @@ Building the API client library requires:

## Installation

### Maven Central (Recommended)

The onesignal-java-client is available on Maven Central. Add the following dependency to your project:

#### Maven users

Add this dependency to your project's POM:
### Maven

```xml
<dependency>
<groupId>com.onesignal</groupId>
<artifactId>onesignal-java-client</artifactId>
<version>5.3.0</version>
<scope>compile</scope>
</dependency>
```

#### Gradle users

Add this dependency to your project's build file:
### Gradle

```groovy
dependencies {
implementation "com.onesignal:onesignal-java-client:5.3.0"
}
implementation "com.onesignal:onesignal-java-client:5.3.0"
```

### Manual Installation
## Configuration

To install the library to your local Maven repository, execute:
Every SDK requires authentication via API keys. Two key types are available:

```shell
mvn clean install
```
- **REST API Key** — required for most endpoints (sending notifications, managing users, etc.). Found in your app's **Settings > Keys & IDs**.
- **Organization API Key** — only required for organization-level endpoints like creating or listing apps. Found in **Organization Settings**.

#### Local Build Dependencies
> **Warning:** Store your API keys in environment variables or a secrets manager. Never commit them to source control.

```groovy
repositories {
mavenCentral() // Needed if the 'onesignal-java-client' jar has been published to maven central.
mavenLocal() // Needed if the 'onesignal-java-client' jar has been published to the local maven repo.
}

dependencies {
implementation "com.onesignal:onesignal-java-client:5.3.0"
}
```
```java
import com.onesignal.client.ApiClient;
import com.onesignal.client.Configuration;
import com.onesignal.client.auth.HttpBearerAuth;
import com.onesignal.client.api.DefaultApi;

### Others
ApiClient defaultClient = Configuration.getDefaultApiClient();

At first generate the JAR by executing:
HttpBearerAuth restApiAuth = (HttpBearerAuth) defaultClient
.getAuthentication("rest_api_key");
restApiAuth.setBearerToken("YOUR_REST_API_KEY");

```shell
mvn clean package
HttpBearerAuth orgApiAuth = (HttpBearerAuth) defaultClient
.getAuthentication("organization_api_key");
orgApiAuth.setBearerToken("YOUR_ORGANIZATION_API_KEY");

DefaultApi client = new DefaultApi(defaultClient);
```

Then manually install the following JARs:
## Send a push notification

```java
import com.onesignal.client.model.Notification;
import com.onesignal.client.model.StringMap;

Notification notification = new Notification();
notification.setAppId("YOUR_APP_ID");

* `target/onesignal-java-client-5.3.0.jar`
* `target/lib/*.jar`
StringMap contents = new StringMap();
contents.en("Hello from OneSignal!");
notification.setContents(contents);

## Getting Started
StringMap headings = new StringMap();
headings.en("Push Notification");
notification.setHeadings(headings);

notification.setIncludedSegments(Arrays.asList("Subscribed Users"));

var response = client.createNotification(notification);
System.out.println("Notification ID: " + response.getId());
```

Please follow the [installation](#installation) instruction and execute the following Java code:
## Send an email

```java
Notification notification = new Notification();
notification.setAppId("YOUR_APP_ID");
notification.setEmailSubject("Important Update");
notification.setEmailBody("<h1>Hello!</h1><p>This is an HTML email.</p>");
notification.setIncludedSegments(Arrays.asList("Subscribed Users"));
notification.setChannelForExternalUserIds("email");

var response = client.createNotification(notification);
```

// Import classes:
import com.onesignal.client.ApiClient;
import com.onesignal.client.ApiException;
import com.onesignal.client.Configuration;
import com.onesignal.client.auth.*;
import com.onesignal.client.models.*;
import com.onesignal.client.api.DefaultApi;
## Send an SMS

public class Example {
private static final String appId = "YOUR_APP_ID";
private static final String restApiKey = "YOUR_REST_API_KEY"; // App REST API key required for most endpoints
private static final String organizationApiKey = "YOUR_ORGANIZATION_API_KEY"; // Organization key is only required for creating new apps and other top-level endpoints

private static Notification createNotification() {
Notification notification = new Notification();
notification.setAppId(appId);
notification.setIsChrome(true);
notification.setIsAnyWeb(true);
notification.setIncludedSegments(Arrays.asList(new String[]{"Subscribed Users"}));
StringMap contentStringMap = new StringMap();
contentStringMap.en("Test");
notification.setContents(contentStringMap);

return notification;
}

public static void main(String[] args) {
// Setting up the client
ApiClient defaultClient = Configuration.getDefaultApiClient();
HttpBearerAuth restApiAuth = (HttpBearerAuth) defaultClient.getAuthentication("rest_api_key");
restApiAuth.setBearerToken(restApiKey);
HttpBearerAuth organizationApiAuth = (HttpBearerAuth) defaultClient.getAuthentication("organization_api_key");
organizationApiAuth.setBearerToken(organizationApiKey);
api = new DefaultApi(defaultClient);

// Setting up the notification
Notification notification = createNotification();

// Sending the request
CreateNotificationSuccessResponse response = api.createNotification(notification);

// Checking the result
System.out.print(response.getId();
}
}
```java
StringMap contents = new StringMap();
contents.en("Your SMS message content here");

Notification notification = new Notification();
notification.setAppId("YOUR_APP_ID");
notification.setContents(contents);
notification.setIncludedSegments(Arrays.asList("Subscribed Users"));
notification.setChannelForExternalUserIds("sms");
notification.setSmsFrom("+15551234567");

var response = client.createNotification(notification);
```

## Documentation for API Endpoints

All URIs are relative to *https://api.onesignal.com*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*DefaultApi* | [**cancelNotification**](docs/DefaultApi.md#cancelNotification) | **DELETE** /notifications/{notification_id} | Stop a scheduled or currently outgoing notification
*DefaultApi* | [**copyTemplateToApp**](docs/DefaultApi.md#copyTemplateToApp) | **POST** /templates/{template_id}/copy_to_app | Copy template to another app
*DefaultApi* | [**createAlias**](docs/DefaultApi.md#createAlias) | **PATCH** /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity |
*DefaultApi* | [**createAliasBySubscription**](docs/DefaultApi.md#createAliasBySubscription) | **PATCH** /apps/{app_id}/subscriptions/{subscription_id}/user/identity |
*DefaultApi* | [**createApiKey**](docs/DefaultApi.md#createApiKey) | **POST** /apps/{app_id}/auth/tokens | Create API key
*DefaultApi* | [**createApp**](docs/DefaultApi.md#createApp) | **POST** /apps | Create an app
*DefaultApi* | [**createCustomEvents**](docs/DefaultApi.md#createCustomEvents) | **POST** /apps/{app_id}/integrations/custom_events | Create custom events
*DefaultApi* | [**createNotification**](docs/DefaultApi.md#createNotification) | **POST** /notifications | Create notification
*DefaultApi* | [**createSegment**](docs/DefaultApi.md#createSegment) | **POST** /apps/{app_id}/segments | Create Segment
*DefaultApi* | [**createSubscription**](docs/DefaultApi.md#createSubscription) | **POST** /apps/{app_id}/users/by/{alias_label}/{alias_id}/subscriptions |
*DefaultApi* | [**createTemplate**](docs/DefaultApi.md#createTemplate) | **POST** /templates | Create template
*DefaultApi* | [**createUser**](docs/DefaultApi.md#createUser) | **POST** /apps/{app_id}/users |
*DefaultApi* | [**deleteAlias**](docs/DefaultApi.md#deleteAlias) | **DELETE** /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity/{alias_label_to_delete} |
*DefaultApi* | [**deleteApiKey**](docs/DefaultApi.md#deleteApiKey) | **DELETE** /apps/{app_id}/auth/tokens/{token_id} | Delete API key
*DefaultApi* | [**deleteSegment**](docs/DefaultApi.md#deleteSegment) | **DELETE** /apps/{app_id}/segments/{segment_id} | Delete Segment
*DefaultApi* | [**deleteSubscription**](docs/DefaultApi.md#deleteSubscription) | **DELETE** /apps/{app_id}/subscriptions/{subscription_id} |
*DefaultApi* | [**deleteTemplate**](docs/DefaultApi.md#deleteTemplate) | **DELETE** /templates/{template_id} | Delete template
*DefaultApi* | [**deleteUser**](docs/DefaultApi.md#deleteUser) | **DELETE** /apps/{app_id}/users/by/{alias_label}/{alias_id} |
*DefaultApi* | [**exportEvents**](docs/DefaultApi.md#exportEvents) | **POST** /notifications/{notification_id}/export_events?app_id&#x3D;{app_id} | Export CSV of Events
*DefaultApi* | [**exportSubscriptions**](docs/DefaultApi.md#exportSubscriptions) | **POST** /players/csv_export?app_id&#x3D;{app_id} | Export CSV of Subscriptions
*DefaultApi* | [**getAliases**](docs/DefaultApi.md#getAliases) | **GET** /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity |
*DefaultApi* | [**getAliasesBySubscription**](docs/DefaultApi.md#getAliasesBySubscription) | **GET** /apps/{app_id}/subscriptions/{subscription_id}/user/identity |
*DefaultApi* | [**getApp**](docs/DefaultApi.md#getApp) | **GET** /apps/{app_id} | View an app
*DefaultApi* | [**getApps**](docs/DefaultApi.md#getApps) | **GET** /apps | View apps
*DefaultApi* | [**getNotification**](docs/DefaultApi.md#getNotification) | **GET** /notifications/{notification_id} | View notification
*DefaultApi* | [**getNotificationHistory**](docs/DefaultApi.md#getNotificationHistory) | **POST** /notifications/{notification_id}/history | Notification History
*DefaultApi* | [**getNotifications**](docs/DefaultApi.md#getNotifications) | **GET** /notifications | View notifications
*DefaultApi* | [**getOutcomes**](docs/DefaultApi.md#getOutcomes) | **GET** /apps/{app_id}/outcomes | View Outcomes
*DefaultApi* | [**getSegments**](docs/DefaultApi.md#getSegments) | **GET** /apps/{app_id}/segments | Get Segments
*DefaultApi* | [**getUser**](docs/DefaultApi.md#getUser) | **GET** /apps/{app_id}/users/by/{alias_label}/{alias_id} |
*DefaultApi* | [**rotateApiKey**](docs/DefaultApi.md#rotateApiKey) | **POST** /apps/{app_id}/auth/tokens/{token_id}/rotate | Rotate API key
*DefaultApi* | [**startLiveActivity**](docs/DefaultApi.md#startLiveActivity) | **POST** /apps/{app_id}/activities/activity/{activity_type} | Start Live Activity
*DefaultApi* | [**transferSubscription**](docs/DefaultApi.md#transferSubscription) | **PATCH** /apps/{app_id}/subscriptions/{subscription_id}/owner |
*DefaultApi* | [**unsubscribeEmailWithToken**](docs/DefaultApi.md#unsubscribeEmailWithToken) | **POST** /apps/{app_id}/notifications/{notification_id}/unsubscribe | Unsubscribe with token
*DefaultApi* | [**updateApiKey**](docs/DefaultApi.md#updateApiKey) | **PATCH** /apps/{app_id}/auth/tokens/{token_id} | Update API key
*DefaultApi* | [**updateApp**](docs/DefaultApi.md#updateApp) | **PUT** /apps/{app_id} | Update an app
*DefaultApi* | [**updateLiveActivity**](docs/DefaultApi.md#updateLiveActivity) | **POST** /apps/{app_id}/live_activities/{activity_id}/notifications | Update a Live Activity via Push
*DefaultApi* | [**updateSubscription**](docs/DefaultApi.md#updateSubscription) | **PATCH** /apps/{app_id}/subscriptions/{subscription_id} |
*DefaultApi* | [**updateSubscriptionByToken**](docs/DefaultApi.md#updateSubscriptionByToken) | **PATCH** /apps/{app_id}/subscriptions_by_token/{token_type}/{token} | Update subscription by token
*DefaultApi* | [**updateTemplate**](docs/DefaultApi.md#updateTemplate) | **PATCH** /templates/{template_id} | Update template
*DefaultApi* | [**updateUser**](docs/DefaultApi.md#updateUser) | **PATCH** /apps/{app_id}/users/by/{alias_label}/{alias_id} |
*DefaultApi* | [**viewApiKeys**](docs/DefaultApi.md#viewApiKeys) | **GET** /apps/{app_id}/auth/tokens | View API keys
*DefaultApi* | [**viewTemplate**](docs/DefaultApi.md#viewTemplate) | **GET** /templates/{template_id} | View template
*DefaultApi* | [**viewTemplates**](docs/DefaultApi.md#viewTemplates) | **GET** /templates | View templates


## Documentation for Models

- [ApiKeyToken](docs/ApiKeyToken.md)
- [ApiKeyTokensListResponse](docs/ApiKeyTokensListResponse.md)
- [App](docs/App.md)
- [BasicNotification](docs/BasicNotification.md)
- [BasicNotificationAllOf](docs/BasicNotificationAllOf.md)
- [BasicNotificationAllOfAndroidBackgroundLayout](docs/BasicNotificationAllOfAndroidBackgroundLayout.md)
- [Button](docs/Button.md)
- [CopyTemplateRequest](docs/CopyTemplateRequest.md)
- [CreateApiKeyRequest](docs/CreateApiKeyRequest.md)
- [CreateApiKeyResponse](docs/CreateApiKeyResponse.md)
- [CreateNotificationSuccessResponse](docs/CreateNotificationSuccessResponse.md)
- [CreateSegmentConflictResponse](docs/CreateSegmentConflictResponse.md)
- [CreateSegmentSuccessResponse](docs/CreateSegmentSuccessResponse.md)
- [CreateTemplateRequest](docs/CreateTemplateRequest.md)
- [CreateUserConflictResponse](docs/CreateUserConflictResponse.md)
- [CreateUserConflictResponseErrorsInner](docs/CreateUserConflictResponseErrorsInner.md)
- [CreateUserConflictResponseErrorsItemsMeta](docs/CreateUserConflictResponseErrorsItemsMeta.md)
- [CustomEvent](docs/CustomEvent.md)
- [CustomEventsRequest](docs/CustomEventsRequest.md)
- [DeliveryData](docs/DeliveryData.md)
- [ExportEventsSuccessResponse](docs/ExportEventsSuccessResponse.md)
- [ExportSubscriptionsRequestBody](docs/ExportSubscriptionsRequestBody.md)
- [ExportSubscriptionsSuccessResponse](docs/ExportSubscriptionsSuccessResponse.md)
- [Filter](docs/Filter.md)
- [FilterExpression](docs/FilterExpression.md)
- [GenericError](docs/GenericError.md)
- [GenericSuccessBoolResponse](docs/GenericSuccessBoolResponse.md)
- [GetNotificationHistoryRequestBody](docs/GetNotificationHistoryRequestBody.md)
- [GetSegmentsSuccessResponse](docs/GetSegmentsSuccessResponse.md)
- [LanguageStringMap](docs/LanguageStringMap.md)
- [Notification](docs/Notification.md)
- [NotificationAllOf](docs/NotificationAllOf.md)
- [NotificationHistorySuccessResponse](docs/NotificationHistorySuccessResponse.md)
- [NotificationSlice](docs/NotificationSlice.md)
- [NotificationTarget](docs/NotificationTarget.md)
- [NotificationWithMeta](docs/NotificationWithMeta.md)
- [NotificationWithMetaAllOf](docs/NotificationWithMetaAllOf.md)
- [Operator](docs/Operator.md)
- [OutcomeData](docs/OutcomeData.md)
- [OutcomesData](docs/OutcomesData.md)
- [PlatformDeliveryData](docs/PlatformDeliveryData.md)
- [PlatformDeliveryDataEmailAllOf](docs/PlatformDeliveryDataEmailAllOf.md)
- [PlatformDeliveryDataSmsAllOf](docs/PlatformDeliveryDataSmsAllOf.md)
- [PropertiesBody](docs/PropertiesBody.md)
- [PropertiesDeltas](docs/PropertiesDeltas.md)
- [PropertiesObject](docs/PropertiesObject.md)
- [Purchase](docs/Purchase.md)
- [RateLimitError](docs/RateLimitError.md)
- [Segment](docs/Segment.md)
- [SegmentData](docs/SegmentData.md)
- [SegmentNotificationTarget](docs/SegmentNotificationTarget.md)
- [StartLiveActivityRequest](docs/StartLiveActivityRequest.md)
- [StartLiveActivitySuccessResponse](docs/StartLiveActivitySuccessResponse.md)
- [Subscription](docs/Subscription.md)
- [SubscriptionBody](docs/SubscriptionBody.md)
- [SubscriptionNotificationTarget](docs/SubscriptionNotificationTarget.md)
- [TemplateResource](docs/TemplateResource.md)
- [TemplatesListResponse](docs/TemplatesListResponse.md)
- [TransferSubscriptionRequestBody](docs/TransferSubscriptionRequestBody.md)
- [UpdateApiKeyRequest](docs/UpdateApiKeyRequest.md)
- [UpdateLiveActivityRequest](docs/UpdateLiveActivityRequest.md)
- [UpdateLiveActivitySuccessResponse](docs/UpdateLiveActivitySuccessResponse.md)
- [UpdateTemplateRequest](docs/UpdateTemplateRequest.md)
- [UpdateUserRequest](docs/UpdateUserRequest.md)
- [User](docs/User.md)
- [UserIdentityBody](docs/UserIdentityBody.md)
- [WebButton](docs/WebButton.md)


## Documentation for Authorization

Authentication schemes defined for the API:
### organization_api_key

- **Type**: HTTP basic authentication

### rest_api_key

- **Type**: HTTP basic authentication


## Recommendation

It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.

## Author

devrel@onesignal.com
## Full API reference

The complete list of API endpoints and their parameters is available in the [DefaultApi documentation](https://github.com/OneSignal/onesignal-java-api/blob/main/docs/DefaultApi.md).

For the underlying REST API, see the [OneSignal API reference](https://documentation.onesignal.com/reference).
Loading
Loading