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
Building the API client library requires:
- Java 1.8+
- Maven (3.8.3+)/Gradle (7.2+)
The onesignal-java-client is available on Maven Central. Add the following dependency to your project:
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>com.onesignal</groupId>
<artifactId>onesignal-java-client</artifactId>
<version>5.3.0</version>
<scope>compile</scope>
</dependency>Add this dependency to your project's build file:
dependencies {
implementation "com.onesignal:onesignal-java-client:5.3.0"
}To install the library to your local Maven repository, execute:
mvn clean installrepositories {
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"
}At first generate the JAR by executing:
mvn clean packageThen manually install the following JARs:
target/onesignal-java-client-5.3.0.jartarget/lib/*.jar
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 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) throws ApiException {
// 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());
}
}All URIs are relative to https://api.onesignal.com
- ApiKeyToken
- ApiKeyTokensListResponse
- App
- BasicNotification
- BasicNotificationAllOf
- BasicNotificationAllOfAndroidBackgroundLayout
- Button
- CopyTemplateRequest
- CreateApiKeyRequest
- CreateApiKeyResponse
- CreateNotificationSuccessResponse
- CreateSegmentConflictResponse
- CreateSegmentSuccessResponse
- CreateTemplateRequest
- CreateUserConflictResponse
- CreateUserConflictResponseErrorsInner
- CreateUserConflictResponseErrorsItemsMeta
- CustomEvent
- CustomEventsRequest
- DeliveryData
- ExportEventsSuccessResponse
- ExportSubscriptionsRequestBody
- ExportSubscriptionsSuccessResponse
- Filter
- FilterExpression
- GenericError
- GenericSuccessBoolResponse
- GetNotificationHistoryRequestBody
- GetSegmentsSuccessResponse
- LanguageStringMap
- Notification
- NotificationAllOf
- NotificationHistorySuccessResponse
- NotificationSlice
- NotificationTarget
- NotificationWithMeta
- NotificationWithMetaAllOf
- Operator
- OutcomeData
- OutcomesData
- PlatformDeliveryData
- PlatformDeliveryDataEmailAllOf
- PlatformDeliveryDataSmsAllOf
- PropertiesBody
- PropertiesDeltas
- PropertiesObject
- Purchase
- RateLimitError
- Segment
- SegmentData
- SegmentNotificationTarget
- StartLiveActivityRequest
- StartLiveActivitySuccessResponse
- Subscription
- SubscriptionBody
- SubscriptionNotificationTarget
- TemplateResource
- TemplatesListResponse
- TransferSubscriptionRequestBody
- UpdateApiKeyRequest
- UpdateLiveActivityRequest
- UpdateLiveActivitySuccessResponse
- UpdateTemplateRequest
- UpdateUserRequest
- User
- UserIdentityBody
- WebButton
Authentication schemes defined for the API:
- Type: HTTP basic authentication
- Type: HTTP basic authentication
It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issues.
