Skip to content

Repository files navigation

onesignal-java-client

Building with an AI agent or LLM? See AGENTS.md for an agent-oriented integration guide — authentication, calling conventions, idempotent retries, and the full API reference.

OneSignal

  • API version: 5.13.0

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

Requirements

Building the API client library requires:

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

Installation

Maven

<dependency>
<groupId>com.onesignal</groupId>
<artifactId>onesignal-java-client</artifactId>
<version>5.13.0</version>
</dependency>

Gradle

implementation "com.onesignal:onesignal-java-client:5.13.0"

Configuration

Every SDK requires authentication via API keys. Two key types are available:

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

Warning: Store your API keys in environment variables or a secrets manager. Never commit them to source control.

importcom.onesignal.client.ApiClient;
importcom.onesignal.client.Configuration;
importcom.onesignal.client.auth.HttpBearerAuth;
importcom.onesignal.client.api.DefaultApi;
ApiClientdefaultClient = Configuration.getDefaultApiClient();
HttpBearerAuthrestApiAuth = (HttpBearerAuth) defaultClient
.getAuthentication("rest_api_key");
restApiAuth.setBearerToken("YOUR_REST_API_KEY");
HttpBearerAuthorgApiAuth = (HttpBearerAuth) defaultClient
.getAuthentication("organization_api_key");
orgApiAuth.setBearerToken("YOUR_ORGANIZATION_API_KEY");
DefaultApiclient = newDefaultApi(defaultClient);

Send a push notification

importcom.onesignal.client.model.Notification;
importcom.onesignal.client.model.StringMap;
Notificationnotification = newNotification();
notification.setAppId("YOUR_APP_ID");
StringMapcontents = newStringMap();
contents.en("Hello from OneSignal!");
notification.setContents(contents);
StringMapheadings = newStringMap();
headings.en("Push Notification");
notification.setHeadings(headings);
notification.setIncludedSegments(Arrays.asList("Subscribed Users"));
varresponse = client.createNotification(notification);
System.out.println("Notification ID: " + response.getId());

Send an email

Notificationnotification = newNotification();
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");
varresponse = client.createNotification(notification);

Send an SMS

StringMapcontents = newStringMap();
contents.en("Your SMS message content here");
Notificationnotification = newNotification();
notification.setAppId("YOUR_APP_ID");
notification.setContents(contents);
notification.setIncludedSegments(Arrays.asList("Subscribed Users"));
notification.setChannelForExternalUserIds("sms");
notification.setSmsFrom("+15551234567");
varresponse = client.createNotification(notification);

Full API reference

The complete list of API endpoints and their parameters is available in the DefaultApi documentation.

For the underlying REST API, see the OneSignal API reference.

About

No description or website provided.

Topics

Resources

Stars

14 stars

Watchers

30 watching

Forks

Releases

Packages

Used by

Contributors

Languages