@@ -5,11 +5,6 @@ OneSignal
55
66A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
77
8- For more information, please visit [ https://onesignal.com ] ( https://onesignal.com )
9-
10- * Automatically generated by the [ OpenAPI Generator] ( https://openapi-generator.tech ) *
11-
12-
138## Requirements
149
1510Building the API client library requires:
@@ -18,261 +13,104 @@ Building the API client library requires:
1813
1914## Installation
2015
21- ### Maven Central (Recommended)
22-
23- The onesignal-java-client is available on Maven Central. Add the following dependency to your project:
24-
25- #### Maven users
26-
27- Add this dependency to your project's POM:
16+ ### Maven
2817
2918``` xml
3019<dependency >
3120 <groupId >com.onesignal</groupId >
3221 <artifactId >onesignal-java-client</artifactId >
3322 <version >5.3.0</version >
34- <scope >compile</scope >
3523</dependency >
3624```
3725
38- #### Gradle users
39-
40- Add this dependency to your project's build file:
26+ ### Gradle
4127
4228``` groovy
43- dependencies {
44- implementation "com.onesignal:onesignal-java-client:5.3.0"
45- }
29+ implementation "com.onesignal:onesignal-java-client:5.3.0"
4630```
4731
48- ### Manual Installation
32+ ## Configuration
4933
50- To install the library to your local Maven repository, execute :
34+ Every SDK requires authentication via API keys. Two key types are available :
5135
52- ``` shell
53- mvn clean install
54- ```
36+ - ** REST API Key** — required for most endpoints (sending notifications, managing users, etc.). Found in your app's ** Settings > Keys & IDs** .
37+ - ** Organization API Key** — only required for organization-level endpoints like creating or listing apps. Found in ** Organization Settings** .
5538
56- #### Local Build Dependencies
39+ > ** Warning: ** Store your API keys in environment variables or a secrets manager. Never commit them to source control.
5740
58- ``` groovy
59- repositories {
60- mavenCentral() // Needed if the 'onesignal-java-client' jar has been published to maven central.
61- mavenLocal() // Needed if the 'onesignal-java-client' jar has been published to the local maven repo.
62- }
63-
64- dependencies {
65- implementation "com.onesignal:onesignal-java-client:5.3.0"
66- }
67- ```
41+ ``` java
42+ import com.onesignal.client.ApiClient ;
43+ import com.onesignal.client.Configuration ;
44+ import com.onesignal.client.auth.HttpBearerAuth ;
45+ import com.onesignal.client.api.DefaultApi ;
6846
69- ### Others
47+ ApiClient defaultClient = Configuration . getDefaultApiClient();
7048
71- At first generate the JAR by executing:
49+ HttpBearerAuth restApiAuth = (HttpBearerAuth ) defaultClient
50+ .getAuthentication(" rest_api_key" );
51+ restApiAuth. setBearerToken(" YOUR_REST_API_KEY" );
7252
73- ``` shell
74- mvn clean package
53+ HttpBearerAuth orgApiAuth = (HttpBearerAuth ) defaultClient
54+ .getAuthentication(" organization_api_key" );
55+ orgApiAuth. setBearerToken(" YOUR_ORGANIZATION_API_KEY" );
56+
57+ DefaultApi client = new DefaultApi (defaultClient);
7558```
7659
77- Then manually install the following JARs:
60+ ## Send a push notification
61+
62+ ``` java
63+ import com.onesignal.client.model.Notification ;
64+ import com.onesignal.client.model.StringMap ;
65+
66+ Notification notification = new Notification ();
67+ notification. setAppId(" YOUR_APP_ID" );
7868
79- * ` target/onesignal-java-client-5.3.0.jar `
80- * ` target/lib/*.jar `
69+ StringMap contents = new StringMap ();
70+ contents. en(" Hello from OneSignal!" );
71+ notification. setContents(contents);
8172
82- ## Getting Started
73+ StringMap headings = new StringMap ();
74+ headings. en(" Push Notification" );
75+ notification. setHeadings(headings);
76+
77+ notification. setIncludedSegments(Arrays . asList(" Subscribed Users" ));
78+
79+ var response = client. createNotification(notification);
80+ System . out. println(" Notification ID: " + response. getId());
81+ ```
8382
84- Please follow the [ installation ] ( #installation ) instruction and execute the following Java code:
83+ ## Send an email
8584
8685``` java
86+ Notification notification = new Notification ();
87+ notification. setAppId(" YOUR_APP_ID" );
88+ notification. setEmailSubject(" Important Update" );
89+ notification. setEmailBody(" <h1>Hello!</h1><p>This is an HTML email.</p>" );
90+ notification. setIncludedSegments(Arrays . asList(" Subscribed Users" ));
91+ notification. setChannelForExternalUserIds(" email" );
92+
93+ var response = client. createNotification(notification);
94+ ```
8795
88- // Import classes:
89- import com.onesignal.client.ApiClient ;
90- import com.onesignal.client.ApiException ;
91- import com.onesignal.client.Configuration ;
92- import com.onesignal.client.auth.* ;
93- import com.onesignal.client.models.* ;
94- import com.onesignal.client.api.DefaultApi ;
96+ ## Send an SMS
9597
96- public class Example {
97- private static final String appId = " YOUR_APP_ID" ;
98- private static final String restApiKey = " YOUR_REST_API_KEY" ; // App REST API key required for most endpoints
99- private static final String organizationApiKey = " YOUR_ORGANIZATION_API_KEY" ; // Organization key is only required for creating new apps and other top-level endpoints
100-
101- private static Notification createNotification () {
102- Notification notification = new Notification ();
103- notification. setAppId(appId);
104- notification. setIsChrome(true );
105- notification. setIsAnyWeb(true );
106- notification. setIncludedSegments(Arrays . asList(new String []{" Subscribed Users" }));
107- StringMap contentStringMap = new StringMap ();
108- contentStringMap. en(" Test" );
109- notification. setContents(contentStringMap);
110-
111- return notification;
112- }
113-
114- public static void main (String [] args ) {
115- // Setting up the client
116- ApiClient defaultClient = Configuration . getDefaultApiClient();
117- HttpBearerAuth restApiAuth = (HttpBearerAuth ) defaultClient. getAuthentication(" rest_api_key" );
118- restApiAuth. setBearerToken(restApiKey);
119- HttpBearerAuth organizationApiAuth = (HttpBearerAuth ) defaultClient. getAuthentication(" organization_api_key" );
120- organizationApiAuth. setBearerToken(organizationApiKey);
121- api = new DefaultApi (defaultClient);
122-
123- // Setting up the notification
124- Notification notification = createNotification();
125-
126- // Sending the request
127- CreateNotificationSuccessResponse response = api. createNotification(notification);
128-
129- // Checking the result
130- System . out. print(response. getId();
131- }
132- }
98+ ``` java
99+ StringMap contents = new StringMap ();
100+ contents. en(" Your SMS message content here" );
101+
102+ Notification notification = new Notification ();
103+ notification. setAppId(" YOUR_APP_ID" );
104+ notification. setContents(contents);
105+ notification. setIncludedSegments(Arrays . asList(" Subscribed Users" ));
106+ notification. setChannelForExternalUserIds(" sms" );
107+ notification. setSmsFrom(" +15551234567" );
133108
109+ var response = client. createNotification(notification);
134110```
135111
136- ## Documentation for API Endpoints
137-
138- All URIs are relative to * https: // api.onesignal.com*
139-
140- Class | Method | HTTP request | Description
141- ------------ | ------------ - | ------------ - | ------------ -
142- * DefaultApi * | [** cancelNotification** ](docs/ DefaultApi . md#cancelNotification) | ** DELETE ** / notifications/ {notification_id} | Stop a scheduled or currently outgoing notification
143- * DefaultApi * | [** copyTemplateToApp** ](docs/ DefaultApi . md#copyTemplateToApp) | ** POST ** / templates/ {template_id}/ copy_to_app | Copy template to another app
144- * DefaultApi * | [** createAlias** ](docs/ DefaultApi . md#createAlias) | ** PATCH ** / apps/ {app_id}/ users/ by/ {alias_label}/ {alias_id}/ identity |
145- * DefaultApi * | [** createAliasBySubscription** ](docs/ DefaultApi . md#createAliasBySubscription) | ** PATCH ** / apps/ {app_id}/ subscriptions/ {subscription_id}/ user/ identity |
146- * DefaultApi * | [** createApiKey** ](docs/ DefaultApi . md#createApiKey) | ** POST ** / apps/ {app_id}/ auth/ tokens | Create API key
147- * DefaultApi * | [** createApp** ](docs/ DefaultApi . md#createApp) | ** POST ** / apps | Create an app
148- * DefaultApi * | [** createCustomEvents** ](docs/ DefaultApi . md#createCustomEvents) | ** POST ** / apps/ {app_id}/ integrations/ custom_events | Create custom events
149- * DefaultApi * | [** createNotification** ](docs/ DefaultApi . md#createNotification) | ** POST ** / notifications | Create notification
150- * DefaultApi * | [** createSegment** ](docs/ DefaultApi . md#createSegment) | ** POST ** / apps/ {app_id}/ segments | Create Segment
151- * DefaultApi * | [** createSubscription** ](docs/ DefaultApi . md#createSubscription) | ** POST ** / apps/ {app_id}/ users/ by/ {alias_label}/ {alias_id}/ subscriptions |
152- * DefaultApi * | [** createTemplate** ](docs/ DefaultApi . md#createTemplate) | ** POST ** / templates | Create template
153- * DefaultApi * | [** createUser** ](docs/ DefaultApi . md#createUser) | ** POST ** / apps/ {app_id}/ users |
154- * DefaultApi * | [** deleteAlias** ](docs/ DefaultApi . md#deleteAlias) | ** DELETE ** / apps/ {app_id}/ users/ by/ {alias_label}/ {alias_id}/ identity/ {alias_label_to_delete} |
155- * DefaultApi * | [** deleteApiKey** ](docs/ DefaultApi . md#deleteApiKey) | ** DELETE ** / apps/ {app_id}/ auth/ tokens/ {token_id} | Delete API key
156- * DefaultApi * | [** deleteSegment** ](docs/ DefaultApi . md#deleteSegment) | ** DELETE ** / apps/ {app_id}/ segments/ {segment_id} | Delete Segment
157- * DefaultApi * | [** deleteSubscription** ](docs/ DefaultApi . md#deleteSubscription) | ** DELETE ** / apps/ {app_id}/ subscriptions/ {subscription_id} |
158- * DefaultApi * | [** deleteTemplate** ](docs/ DefaultApi . md#deleteTemplate) | ** DELETE ** / templates/ {template_id} | Delete template
159- * DefaultApi * | [** deleteUser** ](docs/ DefaultApi . md#deleteUser) | ** DELETE ** / apps/ {app_id}/ users/ by/ {alias_label}/ {alias_id} |
160- * DefaultApi * | [** exportEvents** ](docs/ DefaultApi . md#exportEvents) | ** POST ** / notifications/ {notification_id}/ export_events? app_id& #x3D;{app_id} | Export CSV of Events
161- * DefaultApi * | [** exportSubscriptions** ](docs/ DefaultApi . md#exportSubscriptions) | ** POST ** / players/ csv_export? app_id& #x3D;{app_id} | Export CSV of Subscriptions
162- * DefaultApi * | [** getAliases** ](docs/ DefaultApi . md#getAliases) | ** GET ** / apps/ {app_id}/ users/ by/ {alias_label}/ {alias_id}/ identity |
163- * DefaultApi * | [** getAliasesBySubscription** ](docs/ DefaultApi . md#getAliasesBySubscription) | ** GET ** / apps/ {app_id}/ subscriptions/ {subscription_id}/ user/ identity |
164- * DefaultApi * | [** getApp** ](docs/ DefaultApi . md#getApp) | ** GET ** / apps/ {app_id} | View an app
165- * DefaultApi * | [** getApps** ](docs/ DefaultApi . md#getApps) | ** GET ** / apps | View apps
166- * DefaultApi * | [** getNotification** ](docs/ DefaultApi . md#getNotification) | ** GET ** / notifications/ {notification_id} | View notification
167- * DefaultApi * | [** getNotificationHistory** ](docs/ DefaultApi . md#getNotificationHistory) | ** POST ** / notifications/ {notification_id}/ history | Notification History
168- * DefaultApi * | [** getNotifications** ](docs/ DefaultApi . md#getNotifications) | ** GET ** / notifications | View notifications
169- * DefaultApi * | [** getOutcomes** ](docs/ DefaultApi . md#getOutcomes) | ** GET ** / apps/ {app_id}/ outcomes | View Outcomes
170- * DefaultApi * | [** getSegments** ](docs/ DefaultApi . md#getSegments) | ** GET ** / apps/ {app_id}/ segments | Get Segments
171- * DefaultApi * | [** getUser** ](docs/ DefaultApi . md#getUser) | ** GET ** / apps/ {app_id}/ users/ by/ {alias_label}/ {alias_id} |
172- * DefaultApi * | [** rotateApiKey** ](docs/ DefaultApi . md#rotateApiKey) | ** POST ** / apps/ {app_id}/ auth/ tokens/ {token_id}/ rotate | Rotate API key
173- * DefaultApi * | [** startLiveActivity** ](docs/ DefaultApi . md#startLiveActivity) | ** POST ** / apps/ {app_id}/ activities/ activity/ {activity_type} | Start Live Activity
174- * DefaultApi * | [** transferSubscription** ](docs/ DefaultApi . md#transferSubscription) | ** PATCH ** / apps/ {app_id}/ subscriptions/ {subscription_id}/ owner |
175- * DefaultApi * | [** unsubscribeEmailWithToken** ](docs/ DefaultApi . md#unsubscribeEmailWithToken) | ** POST ** / apps/ {app_id}/ notifications/ {notification_id}/ unsubscribe | Unsubscribe with token
176- * DefaultApi * | [** updateApiKey** ](docs/ DefaultApi . md#updateApiKey) | ** PATCH ** / apps/ {app_id}/ auth/ tokens/ {token_id} | Update API key
177- * DefaultApi * | [** updateApp** ](docs/ DefaultApi . md#updateApp) | ** PUT ** / apps/ {app_id} | Update an app
178- * DefaultApi * | [** updateLiveActivity** ](docs/ DefaultApi . md#updateLiveActivity) | ** POST ** / apps/ {app_id}/ live_activities/ {activity_id}/ notifications | Update a Live Activity via Push
179- * DefaultApi * | [** updateSubscription** ](docs/ DefaultApi . md#updateSubscription) | ** PATCH ** / apps/ {app_id}/ subscriptions/ {subscription_id} |
180- * DefaultApi * | [** updateSubscriptionByToken** ](docs/ DefaultApi . md#updateSubscriptionByToken) | ** PATCH ** / apps/ {app_id}/ subscriptions_by_token/ {token_type}/ {token} | Update subscription by token
181- * DefaultApi * | [** updateTemplate** ](docs/ DefaultApi . md#updateTemplate) | ** PATCH ** / templates/ {template_id} | Update template
182- * DefaultApi * | [** updateUser** ](docs/ DefaultApi . md#updateUser) | ** PATCH ** / apps/ {app_id}/ users/ by/ {alias_label}/ {alias_id} |
183- * DefaultApi * | [** viewApiKeys** ](docs/ DefaultApi . md#viewApiKeys) | ** GET ** / apps/ {app_id}/ auth/ tokens | View API keys
184- * DefaultApi * | [** viewTemplate** ](docs/ DefaultApi . md#viewTemplate) | ** GET ** / templates/ {template_id} | View template
185- * DefaultApi * | [** viewTemplates** ](docs/ DefaultApi . md#viewTemplates) | ** GET ** / templates | View templates
186-
187-
188- ## Documentation for Models
189-
190- - [ApiKeyToken ](docs/ ApiKeyToken . md)
191- - [ApiKeyTokensListResponse ](docs/ ApiKeyTokensListResponse . md)
192- - [App ](docs/ App . md)
193- - [BasicNotification ](docs/ BasicNotification . md)
194- - [BasicNotificationAllOf ](docs/ BasicNotificationAllOf . md)
195- - [BasicNotificationAllOfAndroidBackgroundLayout ](docs/ BasicNotificationAllOfAndroidBackgroundLayout . md)
196- - [Button ](docs/ Button . md)
197- - [CopyTemplateRequest ](docs/ CopyTemplateRequest . md)
198- - [CreateApiKeyRequest ](docs/ CreateApiKeyRequest . md)
199- - [CreateApiKeyResponse ](docs/ CreateApiKeyResponse . md)
200- - [CreateNotificationSuccessResponse ](docs/ CreateNotificationSuccessResponse . md)
201- - [CreateSegmentConflictResponse ](docs/ CreateSegmentConflictResponse . md)
202- - [CreateSegmentSuccessResponse ](docs/ CreateSegmentSuccessResponse . md)
203- - [CreateTemplateRequest ](docs/ CreateTemplateRequest . md)
204- - [CreateUserConflictResponse ](docs/ CreateUserConflictResponse . md)
205- - [CreateUserConflictResponseErrorsInner ](docs/ CreateUserConflictResponseErrorsInner . md)
206- - [CreateUserConflictResponseErrorsItemsMeta ](docs/ CreateUserConflictResponseErrorsItemsMeta . md)
207- - [CustomEvent ](docs/ CustomEvent . md)
208- - [CustomEventsRequest ](docs/ CustomEventsRequest . md)
209- - [DeliveryData ](docs/ DeliveryData . md)
210- - [ExportEventsSuccessResponse ](docs/ ExportEventsSuccessResponse . md)
211- - [ExportSubscriptionsRequestBody ](docs/ ExportSubscriptionsRequestBody . md)
212- - [ExportSubscriptionsSuccessResponse ](docs/ ExportSubscriptionsSuccessResponse . md)
213- - [Filter ](docs/ Filter . md)
214- - [FilterExpression ](docs/ FilterExpression . md)
215- - [GenericError ](docs/ GenericError . md)
216- - [GenericSuccessBoolResponse ](docs/ GenericSuccessBoolResponse . md)
217- - [GetNotificationHistoryRequestBody ](docs/ GetNotificationHistoryRequestBody . md)
218- - [GetSegmentsSuccessResponse ](docs/ GetSegmentsSuccessResponse . md)
219- - [LanguageStringMap ](docs/ LanguageStringMap . md)
220- - [Notification ](docs/ Notification . md)
221- - [NotificationAllOf ](docs/ NotificationAllOf . md)
222- - [NotificationHistorySuccessResponse ](docs/ NotificationHistorySuccessResponse . md)
223- - [NotificationSlice ](docs/ NotificationSlice . md)
224- - [NotificationTarget ](docs/ NotificationTarget . md)
225- - [NotificationWithMeta ](docs/ NotificationWithMeta . md)
226- - [NotificationWithMetaAllOf ](docs/ NotificationWithMetaAllOf . md)
227- - [Operator ](docs/ Operator . md)
228- - [OutcomeData ](docs/ OutcomeData . md)
229- - [OutcomesData ](docs/ OutcomesData . md)
230- - [PlatformDeliveryData ](docs/ PlatformDeliveryData . md)
231- - [PlatformDeliveryDataEmailAllOf ](docs/ PlatformDeliveryDataEmailAllOf . md)
232- - [PlatformDeliveryDataSmsAllOf ](docs/ PlatformDeliveryDataSmsAllOf . md)
233- - [PropertiesBody ](docs/ PropertiesBody . md)
234- - [PropertiesDeltas ](docs/ PropertiesDeltas . md)
235- - [PropertiesObject ](docs/ PropertiesObject . md)
236- - [Purchase ](docs/ Purchase . md)
237- - [RateLimitError ](docs/ RateLimitError . md)
238- - [Segment ](docs/ Segment . md)
239- - [SegmentData ](docs/ SegmentData . md)
240- - [SegmentNotificationTarget ](docs/ SegmentNotificationTarget . md)
241- - [StartLiveActivityRequest ](docs/ StartLiveActivityRequest . md)
242- - [StartLiveActivitySuccessResponse ](docs/ StartLiveActivitySuccessResponse . md)
243- - [Subscription ](docs/ Subscription . md)
244- - [SubscriptionBody ](docs/ SubscriptionBody . md)
245- - [SubscriptionNotificationTarget ](docs/ SubscriptionNotificationTarget . md)
246- - [TemplateResource ](docs/ TemplateResource . md)
247- - [TemplatesListResponse ](docs/ TemplatesListResponse . md)
248- - [TransferSubscriptionRequestBody ](docs/ TransferSubscriptionRequestBody . md)
249- - [UpdateApiKeyRequest ](docs/ UpdateApiKeyRequest . md)
250- - [UpdateLiveActivityRequest ](docs/ UpdateLiveActivityRequest . md)
251- - [UpdateLiveActivitySuccessResponse ](docs/ UpdateLiveActivitySuccessResponse . md)
252- - [UpdateTemplateRequest ](docs/ UpdateTemplateRequest . md)
253- - [UpdateUserRequest ](docs/ UpdateUserRequest . md)
254- - [User ](docs/ User . md)
255- - [UserIdentityBody ](docs/ UserIdentityBody . md)
256- - [WebButton ](docs/ WebButton . md)
257-
258-
259- ## Documentation for Authorization
260-
261- Authentication schemes defined for the API :
262- ### organization_api_key
263-
264- - ** Type ** : HTTP basic authentication
265-
266- ### rest_api_key
267-
268- - ** Type ** : HTTP basic authentication
269-
270-
271- ## Recommendation
272-
273- It ' s recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.
274-
275- ## Author
276-
277- devrel@onesignal.com
112+ ## Full API reference
113+
114+ The complete list of API endpoints and their parameters is available in the [ DefaultApi documentation] ( https://github.com/OneSignal/onesignal-java-api/blob/main/docs/DefaultApi.md ) .
278115
116+ For the underlying REST API, see the [ OneSignal API reference] ( https://documentation.onesignal.com/reference ) .
0 commit comments