Java Client SDK

The OneSignal Java client is a server OneSignal SDK for Java. Integrate OneSignal with your backend events, data, and more.

Read the blog post!

Requirements

Building the API client library requires:

  1. Java 1.8+
  2. Maven (3.8.3+)/Gradle (7.2+)

Installation

Clone the repository into your machine:

git clone https://github.com/OneSignal/onesignal-java-client

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>org.openapitools</groupId>
  <artifactId>onesignal-java-client</artifactId>
  <version>1.0.1</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

  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 "org.openapitools:onesignal-java-client:1.0.1"
  }

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/onesignal-java-client-1.0.1.jar
  • target/lib/*.jar

Getting started

Import following packages:

// 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;

Create a client and setup authorization:

String appKeyToken = "YOUR_APP_KEY";
String userKeyToken = "YOUR_USER_TOKEN";

ApiClient defaultClient = Configuration.getDefaultApiClient();
HttpBearerAuth appKey = (HttpBearerAuth) defaultClient.getAuthentication("app_key");
appKey.setBearerToken(appKeyToken);
HttpBearerAuth userKey = (HttpBearerAuth) defaultClient.getAuthentication("user_key");
userKey.setBearerToken(userKeyToken);
api = new DefaultApi(defaultClient);

Documentation for API Endpoints

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

ClassMethodHTTP requestDescription
DefaultApicancelNotificationDELETE /notifications/{notification_id}Stop a scheduled or currently outgoing notification
DefaultApicreateAppPOST /appsCreate an app
DefaultApicreateNotificationPOST /notificationsCreate notification
DefaultApicreatePlayerPOST /playersAdd a device
DefaultApicreateSegmentsPOST /apps/{app_id}/segmentsCreate Segments
DefaultApideletePlayerDELETE /players/{player_id}Delete a user record
DefaultApideleteSegmentsDELETE /apps/{app_id}/segments/{segment_id}Delete Segments
DefaultApiexportPlayersPOST /players/csv_export?app_id={app_id}CSV export
DefaultApigetAppGET /apps/{app_id}View an app
DefaultApigetAppsGET /appsView apps
DefaultApigetNotificationGET /notifications/{notification_id}View notification
DefaultApigetNotificationHistoryPOST /notifications/{notification_id}/historyNotification History
DefaultApigetNotificationsGET /notificationsView notifications
DefaultApigetOutcomesGET /apps/{app_id}/outcomesView Outcomes
DefaultApigetPlayerGET /players/{player_id}View device
DefaultApigetPlayersGET /playersView devices
DefaultApiupdateAppPUT /apps/{app_id}Update an app
DefaultApiupdatePlayerPUT /players/{player_id}Edit device
DefaultApiupdatePlayerTagsPUT /apps/{app_id}/users/{external_user_id}Edit tags with external user id

Documentation for Models

Documentation for Authorization

Authentication schemes defined for the API:

app_key

  • Type: HTTP basic authentication

user_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.