Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

OneSignal/onesignal-java-api

Open more actions menu

Repository files navigation

onesignal-java-client

OneSignal

  • API version: 5.3.0

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

Automatically generated by the OpenAPI Generator

Requirements

Building the API client library requires:

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

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:

<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:

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

Manual Installation

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

mvn clean install

Local Build Dependencies

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"
}

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

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

Getting Started

Please follow the installation instruction and execute the following Java code:

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

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();
  }
}

Documentation for API Endpoints

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

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

Documentation for Models

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

Packages

No packages published

Contributors 5

Morty Proxy This is a proxified and sanitized view of the page, visit original site.