OneSignal Java Client SDK is Now Available
We are pleased to announce that the OneSignal Java API Client Library is now available. This new Java client supports developers using OneSignal by facilitating integrating the OneSignal REST API with your backend events, data, and more. This release is part of our ongoing initiative to add server SDKs across various languages and technologies.
Java is one of the most popular programming languages in the world and we are happy to support it!
Requirements
Building the API client library requires:
- Java 1.8+
- Maven (3.8.3+)/Gradle (7.2+)
Installation
Clone the repository into your machine:
git clone https://github.com/OneSignal/onesignal-java-api
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 {
mavenLocal() // If the 'onesignal-java-api' jar has been published to the local maven repo.
}
dependencies {
implementation "org.openapitools:onesignal-java-api:1.0.1"
}
Others
At first generate the JAR by executing:
mvn clean package
Then manually install the following JARs:
target/onesignal-java-api-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);
Follow our instructions here to create notification, get outcomes etc.
Reference
Visit our REST API Reference documentation for a complete list of our supported endpoints.
Visit our Java API reference for a list of supported functions and view implementation examples in Java.
Share Your Feedback
If you’ve had a chance to use our new Java SDK and have any feedback or suggestions you’d like to share, please reach out to us on the GitHub repository or our Discord server.
If you encounter any bugs or technical issues while using our new Java SDK, we want to know so we can make things right. Please be sure to file a report on our GitHub repository.
If you’ve found the plugin helpful, we’d appreciate it if you left us a review on G2.
View Java Client SDK Documentation