/onesignal-java-api

Primary LanguageJavaOtherNOASSERTION

onesignal-java-client

OneSignal

  • API version: 1.2.2
    • Build date: 2023-08-01T23:27:12.168Z[Etc/UTC]

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

First, clone the repo, simply execute:

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

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

After you build and install to your local Maven repo ou deploy to the project repository, add this dependency to your project's POM:

<dependency>
  <groupId>org.openapitools</groupId>
  <artifactId>onesignal-java-client</artifactId>
  <version>1.2.2</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.2.2"
  }

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

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

Getting Started

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

// Import classes:
import java.util.Arrays;
import com.onesignal.client.ApiClient;
import com.onesignal.client.ApiException;
import com.onesignal.client.Configuration;
import com.onesignal.client.auth.*;
import com.onesignal.client.model.CreateNotificationSuccessResponse;
import com.onesignal.client.model.Notification;
import com.onesignal.client.model.StringMap;
import com.onesignal.client.api.DefaultApi;

public class Example {
  private static final String appId = "YOUR_APP_ID";
  private static final String appKeyToken = "YOUR_APP_KEY";
  private static final String userKeyToken = "YOUR_USER_TOKEN";

  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) throws ApiException {
    // Setting up the client
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    HttpBearerAuth appKey = (HttpBearerAuth) defaultClient.getAuthentication("app_key");
    appKey.setBearerToken(appKeyToken);
    HttpBearerAuth userKey = (HttpBearerAuth) defaultClient.getAuthentication("user_key");
    userKey.setBearerToken(userKeyToken);
    DefaultApi 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://onesignal.com/api/v1

Class Method HTTP request Description
DefaultApi beginLiveActivity POST /apps/{app_id}/live_activities/{activity_id}/token Start Live Activity
DefaultApi cancelNotification DELETE /notifications/{notification_id} Stop a scheduled or currently outgoing notification
DefaultApi createApp POST /apps Create an app
DefaultApi createNotification POST /notifications Create notification
DefaultApi createPlayer POST /players Add a device
DefaultApi createSegments POST /apps/{app_id}/segments Create Segments
DefaultApi createSubscription POST /apps/{app_id}/users/by/{alias_label}/{alias_id}/subscriptions
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 deletePlayer DELETE /players/{player_id} Delete a user record
DefaultApi deleteSegments DELETE /apps/{app_id}/segments/{segment_id} Delete Segments
DefaultApi deleteSubscription DELETE /apps/{app_id}/subscriptions/{subscription_id}
DefaultApi deleteUser DELETE /apps/{app_id}/users/by/{alias_label}/{alias_id}
DefaultApi endLiveActivity DELETE /apps/{app_id}/live_activities/{activity_id}/token/{subscription_id} Stop Live Activity
DefaultApi exportEvents POST /notifications/{notification_id}/export_events?app_id={app_id} Export CSV of Events
DefaultApi exportPlayers POST /players/csv_export?app_id={app_id} Export CSV of Players
DefaultApi fetchAliases GET /apps/{app_id}/subscriptions/{subscription_id}/user/identity
DefaultApi fetchUser GET /apps/{app_id}/users/by/{alias_label}/{alias_id}
DefaultApi fetchUserIdentity GET /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity
DefaultApi getApp GET /apps/{app_id} View an app
DefaultApi getApps GET /apps View apps
DefaultApi getEligibleIams GET /apps/{app_id}/subscriptions/{subscription_id}/iams
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 getPlayer GET /players/{player_id} View device
DefaultApi getPlayers GET /players View devices
DefaultApi identifyUserByAlias PATCH /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity
DefaultApi identifyUserBySubscriptionId PATCH /apps/{app_id}/subscriptions/{subscription_id}/user/identity
DefaultApi transferSubscription PATCH /apps/{app_id}/subscriptions/{subscription_id}/owner
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 updatePlayer PUT /players/{player_id} Edit device
DefaultApi updatePlayerTags PUT /apps/{app_id}/users/{external_user_id} Edit tags with external user id
DefaultApi updateSubscription PATCH /apps/{app_id}/subscriptions/{subscription_id}
DefaultApi updateUser PATCH /apps/{app_id}/users/by/{alias_label}/{alias_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.

Author

devrel@onesignal.com