|
1 | | -<h1 align="center">Welcome to @onesignal/python-onesignal 👋</h1> |
| 1 | +<h1 align="center">Welcome to onesignal-python-api</h1> |
2 | 2 | <p> |
3 | 3 | <a href="https://pypi.org/project/onesignal-python-api/" target="_blank"> |
4 | 4 | <img alt="Version" src="https://img.shields.io/pypi/v/onesignal-python-api"> |
5 | 5 | </a> |
6 | | - <a href="https://github.com/OneSignal/python-onesignal#readme" target="_blank"> |
| 6 | + <a href="https://github.com/OneSignal/onesignal-python-api#readme" target="_blank"> |
7 | 7 | <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" /> |
8 | 8 | </a> |
9 | | - <a href="https://github.com/OneSignal/python-onesignal/graphs/commit-activity" target="_blank"> |
| 9 | + <a href="https://github.com/OneSignal/onesignal-python-api/graphs/commit-activity" target="_blank"> |
10 | 10 | <img alt="Maintenance" src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" /> |
11 | 11 | </a> |
12 | | - <a href="https://twitter.com/onesignal" target="_blank"> |
13 | | - <img alt="Twitter: onesignal" src="https://img.shields.io/twitter/follow/onesignal.svg?style=social" /> |
14 | | - </a> |
15 | 12 | </p> |
16 | 13 |
|
17 | 14 | A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com |
18 | 15 |
|
19 | 16 | - API version: 5.3.0 |
20 | 17 | - Package version: 5.3.0 |
21 | | -- Build package: org.openapitools.codegen.languages.PythonClientCodegen |
22 | 18 |
|
23 | | -## Requirements. |
| 19 | +## Requirements |
24 | 20 |
|
25 | 21 | Python >=3.6 |
26 | 22 |
|
27 | | -## Installation & Usage |
28 | | -### pip install |
| 23 | +## Installation |
| 24 | + |
29 | 25 | ```sh |
30 | 26 | pip install onesignal-python-api |
31 | 27 | ``` |
32 | 28 |
|
33 | | -You can also install directly from GitHub using: |
| 29 | +## Configuration |
34 | 30 |
|
35 | | -```sh |
36 | | -pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git |
37 | | -``` |
| 31 | +Every SDK requires authentication via API keys. Two key types are available: |
38 | 32 |
|
39 | | -You may need to run `pip` with root permission: |
40 | | -```sh |
41 | | -sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git |
42 | | -``` |
43 | | -### Setuptools |
| 33 | +- **REST API Key** — required for most endpoints (sending notifications, managing users, etc.). Found in your app's **Settings > Keys & IDs**. |
| 34 | +- **Organization API Key** — only required for organization-level endpoints like creating or listing apps. Found in **Organization Settings**. |
44 | 35 |
|
45 | | -Install via [Setuptools](http://pypi.python.org/pypi/setuptools). |
| 36 | +> **Warning:** Store your API keys in environment variables or a secrets manager. Never commit them to source control. |
46 | 37 |
|
47 | | -```sh |
48 | | -python setup.py install --user |
49 | | -``` |
| 38 | +```python |
| 39 | +import onesignal |
| 40 | +from onesignal.api import default_api |
50 | 41 |
|
51 | | -To install the package for all users: |
52 | | -```sh |
53 | | -sudo python setup.py install |
54 | | -``` |
| 42 | +configuration = onesignal.Configuration( |
| 43 | + rest_api_key='YOUR_REST_API_KEY', |
| 44 | + organization_api_key='YOUR_ORGANIZATION_API_KEY', |
| 45 | +) |
55 | 46 |
|
56 | | -## Getting Started |
| 47 | +with onesignal.ApiClient(configuration) as api_client: |
| 48 | + client = default_api.DefaultApi(api_client) |
| 49 | +``` |
57 | 50 |
|
58 | | -Please follow the [installation procedure](#installation--usage) and then run the following: |
| 51 | +## Send a push notification |
59 | 52 |
|
60 | 53 | ```python |
61 | | -import onesignal |
62 | | -from onesignal.api import default_api |
| 54 | +notification = onesignal.Notification( |
| 55 | + app_id='YOUR_APP_ID', |
| 56 | + contents=onesignal.StringMap(en='Hello from OneSignal!'), |
| 57 | + headings=onesignal.StringMap(en='Push Notification'), |
| 58 | + included_segments=['Subscribed Users'], |
| 59 | +) |
63 | 60 |
|
64 | | -# See configuration.py for a list of all supported configuration parameters. |
65 | | -# Some of the OneSignal endpoints require ORGANIZATION_API_KEY token for authorization, while others require REST_API_KEY. |
66 | | -# We recommend adding both of them in the configuration page so that you will not need to figure it out yourself. |
67 | | -configuration = onesignal.Configuration( |
68 | | - rest_api_key = "YOUR_REST_API_KEY", # App REST API key required for most endpoints |
69 | | - organization_api_key = "YOUR_ORGANIZATION_KEY" # Organization key is only required for creating new apps and other top-level endpoints |
| 61 | +response = client.create_notification(notification) |
| 62 | +print('Notification ID:', response.id) |
| 63 | +``` |
| 64 | + |
| 65 | +## Send an email |
| 66 | + |
| 67 | +```python |
| 68 | +notification = onesignal.Notification( |
| 69 | + app_id='YOUR_APP_ID', |
| 70 | + email_subject='Important Update', |
| 71 | + email_body='<h1>Hello!</h1><p>This is an HTML email.</p>', |
| 72 | + included_segments=['Subscribed Users'], |
| 73 | + channel_for_external_user_ids='email', |
70 | 74 | ) |
71 | 75 |
|
| 76 | +response = client.create_notification(notification) |
| 77 | +``` |
| 78 | + |
| 79 | +## Send an SMS |
72 | 80 |
|
73 | | -# Enter a context with an instance of the API client |
74 | | -with onesignal.ApiClient(configuration) as api_client: |
75 | | - # Create an instance of the API class |
76 | | - api_instance = default_api.DefaultApi(api_client) |
| 81 | +```python |
| 82 | +notification = onesignal.Notification( |
| 83 | + app_id='YOUR_APP_ID', |
| 84 | + contents=onesignal.StringMap(en='Your SMS message content here'), |
| 85 | + included_segments=['Subscribed Users'], |
| 86 | + channel_for_external_user_ids='sms', |
| 87 | + sms_from='+15551234567', |
| 88 | +) |
| 89 | + |
| 90 | +response = client.create_notification(notification) |
77 | 91 | ``` |
78 | 92 |
|
79 | | -## Documentation for API Endpoints |
80 | | - |
81 | | -All URIs are relative to *https://api.onesignal.com* |
82 | | - |
83 | | -Class | Method | HTTP request | Description |
84 | | ------------- | ------------- | ------------- | ------------- |
85 | | -*DefaultApi* | [**cancel_notification**](docs/DefaultApi.md#cancel_notification) | **DELETE** /notifications/{notification_id} | Stop a scheduled or currently outgoing notification |
86 | | -*DefaultApi* | [**copy_template_to_app**](docs/DefaultApi.md#copy_template_to_app) | **POST** /templates/{template_id}/copy_to_app | Copy template to another app |
87 | | -*DefaultApi* | [**create_alias**](docs/DefaultApi.md#create_alias) | **PATCH** /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity | |
88 | | -*DefaultApi* | [**create_alias_by_subscription**](docs/DefaultApi.md#create_alias_by_subscription) | **PATCH** /apps/{app_id}/subscriptions/{subscription_id}/user/identity | |
89 | | -*DefaultApi* | [**create_api_key**](docs/DefaultApi.md#create_api_key) | **POST** /apps/{app_id}/auth/tokens | Create API key |
90 | | -*DefaultApi* | [**create_app**](docs/DefaultApi.md#create_app) | **POST** /apps | Create an app |
91 | | -*DefaultApi* | [**create_custom_events**](docs/DefaultApi.md#create_custom_events) | **POST** /apps/{app_id}/integrations/custom_events | Create custom events |
92 | | -*DefaultApi* | [**create_notification**](docs/DefaultApi.md#create_notification) | **POST** /notifications | Create notification |
93 | | -*DefaultApi* | [**create_segment**](docs/DefaultApi.md#create_segment) | **POST** /apps/{app_id}/segments | Create Segment |
94 | | -*DefaultApi* | [**create_subscription**](docs/DefaultApi.md#create_subscription) | **POST** /apps/{app_id}/users/by/{alias_label}/{alias_id}/subscriptions | |
95 | | -*DefaultApi* | [**create_template**](docs/DefaultApi.md#create_template) | **POST** /templates | Create template |
96 | | -*DefaultApi* | [**create_user**](docs/DefaultApi.md#create_user) | **POST** /apps/{app_id}/users | |
97 | | -*DefaultApi* | [**delete_alias**](docs/DefaultApi.md#delete_alias) | **DELETE** /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity/{alias_label_to_delete} | |
98 | | -*DefaultApi* | [**delete_api_key**](docs/DefaultApi.md#delete_api_key) | **DELETE** /apps/{app_id}/auth/tokens/{token_id} | Delete API key |
99 | | -*DefaultApi* | [**delete_segment**](docs/DefaultApi.md#delete_segment) | **DELETE** /apps/{app_id}/segments/{segment_id} | Delete Segment |
100 | | -*DefaultApi* | [**delete_subscription**](docs/DefaultApi.md#delete_subscription) | **DELETE** /apps/{app_id}/subscriptions/{subscription_id} | |
101 | | -*DefaultApi* | [**delete_template**](docs/DefaultApi.md#delete_template) | **DELETE** /templates/{template_id} | Delete template |
102 | | -*DefaultApi* | [**delete_user**](docs/DefaultApi.md#delete_user) | **DELETE** /apps/{app_id}/users/by/{alias_label}/{alias_id} | |
103 | | -*DefaultApi* | [**export_events**](docs/DefaultApi.md#export_events) | **POST** /notifications/{notification_id}/export_events?app_id={app_id} | Export CSV of Events |
104 | | -*DefaultApi* | [**export_subscriptions**](docs/DefaultApi.md#export_subscriptions) | **POST** /players/csv_export?app_id={app_id} | Export CSV of Subscriptions |
105 | | -*DefaultApi* | [**get_aliases**](docs/DefaultApi.md#get_aliases) | **GET** /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity | |
106 | | -*DefaultApi* | [**get_aliases_by_subscription**](docs/DefaultApi.md#get_aliases_by_subscription) | **GET** /apps/{app_id}/subscriptions/{subscription_id}/user/identity | |
107 | | -*DefaultApi* | [**get_app**](docs/DefaultApi.md#get_app) | **GET** /apps/{app_id} | View an app |
108 | | -*DefaultApi* | [**get_apps**](docs/DefaultApi.md#get_apps) | **GET** /apps | View apps |
109 | | -*DefaultApi* | [**get_notification**](docs/DefaultApi.md#get_notification) | **GET** /notifications/{notification_id} | View notification |
110 | | -*DefaultApi* | [**get_notification_history**](docs/DefaultApi.md#get_notification_history) | **POST** /notifications/{notification_id}/history | Notification History |
111 | | -*DefaultApi* | [**get_notifications**](docs/DefaultApi.md#get_notifications) | **GET** /notifications | View notifications |
112 | | -*DefaultApi* | [**get_outcomes**](docs/DefaultApi.md#get_outcomes) | **GET** /apps/{app_id}/outcomes | View Outcomes |
113 | | -*DefaultApi* | [**get_segments**](docs/DefaultApi.md#get_segments) | **GET** /apps/{app_id}/segments | Get Segments |
114 | | -*DefaultApi* | [**get_user**](docs/DefaultApi.md#get_user) | **GET** /apps/{app_id}/users/by/{alias_label}/{alias_id} | |
115 | | -*DefaultApi* | [**rotate_api_key**](docs/DefaultApi.md#rotate_api_key) | **POST** /apps/{app_id}/auth/tokens/{token_id}/rotate | Rotate API key |
116 | | -*DefaultApi* | [**start_live_activity**](docs/DefaultApi.md#start_live_activity) | **POST** /apps/{app_id}/activities/activity/{activity_type} | Start Live Activity |
117 | | -*DefaultApi* | [**transfer_subscription**](docs/DefaultApi.md#transfer_subscription) | **PATCH** /apps/{app_id}/subscriptions/{subscription_id}/owner | |
118 | | -*DefaultApi* | [**unsubscribe_email_with_token**](docs/DefaultApi.md#unsubscribe_email_with_token) | **POST** /apps/{app_id}/notifications/{notification_id}/unsubscribe | Unsubscribe with token |
119 | | -*DefaultApi* | [**update_api_key**](docs/DefaultApi.md#update_api_key) | **PATCH** /apps/{app_id}/auth/tokens/{token_id} | Update API key |
120 | | -*DefaultApi* | [**update_app**](docs/DefaultApi.md#update_app) | **PUT** /apps/{app_id} | Update an app |
121 | | -*DefaultApi* | [**update_live_activity**](docs/DefaultApi.md#update_live_activity) | **POST** /apps/{app_id}/live_activities/{activity_id}/notifications | Update a Live Activity via Push |
122 | | -*DefaultApi* | [**update_subscription**](docs/DefaultApi.md#update_subscription) | **PATCH** /apps/{app_id}/subscriptions/{subscription_id} | |
123 | | -*DefaultApi* | [**update_subscription_by_token**](docs/DefaultApi.md#update_subscription_by_token) | **PATCH** /apps/{app_id}/subscriptions_by_token/{token_type}/{token} | Update subscription by token |
124 | | -*DefaultApi* | [**update_template**](docs/DefaultApi.md#update_template) | **PATCH** /templates/{template_id} | Update template |
125 | | -*DefaultApi* | [**update_user**](docs/DefaultApi.md#update_user) | **PATCH** /apps/{app_id}/users/by/{alias_label}/{alias_id} | |
126 | | -*DefaultApi* | [**view_api_keys**](docs/DefaultApi.md#view_api_keys) | **GET** /apps/{app_id}/auth/tokens | View API keys |
127 | | -*DefaultApi* | [**view_template**](docs/DefaultApi.md#view_template) | **GET** /templates/{template_id} | View template |
128 | | -*DefaultApi* | [**view_templates**](docs/DefaultApi.md#view_templates) | **GET** /templates | View templates |
129 | | - |
130 | | - |
131 | | -## Documentation For Models |
132 | | - |
133 | | - - [ApiKeyToken](docs/ApiKeyToken.md) |
134 | | - - [ApiKeyTokensListResponse](docs/ApiKeyTokensListResponse.md) |
135 | | - - [App](docs/App.md) |
136 | | - - [Apps](docs/Apps.md) |
137 | | - - [BasicNotification](docs/BasicNotification.md) |
138 | | - - [BasicNotificationAllOf](docs/BasicNotificationAllOf.md) |
139 | | - - [BasicNotificationAllOfAndroidBackgroundLayout](docs/BasicNotificationAllOfAndroidBackgroundLayout.md) |
140 | | - - [Button](docs/Button.md) |
141 | | - - [CopyTemplateRequest](docs/CopyTemplateRequest.md) |
142 | | - - [CreateApiKeyRequest](docs/CreateApiKeyRequest.md) |
143 | | - - [CreateApiKeyResponse](docs/CreateApiKeyResponse.md) |
144 | | - - [CreateNotificationSuccessResponse](docs/CreateNotificationSuccessResponse.md) |
145 | | - - [CreateSegmentConflictResponse](docs/CreateSegmentConflictResponse.md) |
146 | | - - [CreateSegmentSuccessResponse](docs/CreateSegmentSuccessResponse.md) |
147 | | - - [CreateTemplateRequest](docs/CreateTemplateRequest.md) |
148 | | - - [CreateUserConflictResponse](docs/CreateUserConflictResponse.md) |
149 | | - - [CreateUserConflictResponseErrorsInner](docs/CreateUserConflictResponseErrorsInner.md) |
150 | | - - [CreateUserConflictResponseErrorsItemsMeta](docs/CreateUserConflictResponseErrorsItemsMeta.md) |
151 | | - - [CustomEvent](docs/CustomEvent.md) |
152 | | - - [CustomEventsRequest](docs/CustomEventsRequest.md) |
153 | | - - [DeliveryData](docs/DeliveryData.md) |
154 | | - - [ExportEventsSuccessResponse](docs/ExportEventsSuccessResponse.md) |
155 | | - - [ExportSubscriptionsRequestBody](docs/ExportSubscriptionsRequestBody.md) |
156 | | - - [ExportSubscriptionsSuccessResponse](docs/ExportSubscriptionsSuccessResponse.md) |
157 | | - - [Filter](docs/Filter.md) |
158 | | - - [FilterExpression](docs/FilterExpression.md) |
159 | | - - [GenericError](docs/GenericError.md) |
160 | | - - [GenericSuccessBoolResponse](docs/GenericSuccessBoolResponse.md) |
161 | | - - [GetNotificationHistoryRequestBody](docs/GetNotificationHistoryRequestBody.md) |
162 | | - - [GetSegmentsSuccessResponse](docs/GetSegmentsSuccessResponse.md) |
163 | | - - [IdentityObject](docs/IdentityObject.md) |
164 | | - - [IncludeAliases](docs/IncludeAliases.md) |
165 | | - - [LanguageStringMap](docs/LanguageStringMap.md) |
166 | | - - [Notification](docs/Notification.md) |
167 | | - - [NotificationAllOf](docs/NotificationAllOf.md) |
168 | | - - [NotificationHistorySuccessResponse](docs/NotificationHistorySuccessResponse.md) |
169 | | - - [NotificationSlice](docs/NotificationSlice.md) |
170 | | - - [NotificationTarget](docs/NotificationTarget.md) |
171 | | - - [NotificationWithMeta](docs/NotificationWithMeta.md) |
172 | | - - [NotificationWithMetaAllOf](docs/NotificationWithMetaAllOf.md) |
173 | | - - [Operator](docs/Operator.md) |
174 | | - - [OutcomeData](docs/OutcomeData.md) |
175 | | - - [OutcomesData](docs/OutcomesData.md) |
176 | | - - [PlatformDeliveryData](docs/PlatformDeliveryData.md) |
177 | | - - [PlatformDeliveryDataEmailAllOf](docs/PlatformDeliveryDataEmailAllOf.md) |
178 | | - - [PlatformDeliveryDataSmsAllOf](docs/PlatformDeliveryDataSmsAllOf.md) |
179 | | - - [PropertiesBody](docs/PropertiesBody.md) |
180 | | - - [PropertiesDeltas](docs/PropertiesDeltas.md) |
181 | | - - [PropertiesObject](docs/PropertiesObject.md) |
182 | | - - [Purchase](docs/Purchase.md) |
183 | | - - [RateLimitError](docs/RateLimitError.md) |
184 | | - - [Segment](docs/Segment.md) |
185 | | - - [SegmentData](docs/SegmentData.md) |
186 | | - - [SegmentNotificationTarget](docs/SegmentNotificationTarget.md) |
187 | | - - [StartLiveActivityRequest](docs/StartLiveActivityRequest.md) |
188 | | - - [StartLiveActivitySuccessResponse](docs/StartLiveActivitySuccessResponse.md) |
189 | | - - [Subscription](docs/Subscription.md) |
190 | | - - [SubscriptionBody](docs/SubscriptionBody.md) |
191 | | - - [SubscriptionNotificationTarget](docs/SubscriptionNotificationTarget.md) |
192 | | - - [TemplateResource](docs/TemplateResource.md) |
193 | | - - [TemplatesListResponse](docs/TemplatesListResponse.md) |
194 | | - - [TransferSubscriptionRequestBody](docs/TransferSubscriptionRequestBody.md) |
195 | | - - [UpdateApiKeyRequest](docs/UpdateApiKeyRequest.md) |
196 | | - - [UpdateLiveActivityRequest](docs/UpdateLiveActivityRequest.md) |
197 | | - - [UpdateLiveActivitySuccessResponse](docs/UpdateLiveActivitySuccessResponse.md) |
198 | | - - [UpdateTemplateRequest](docs/UpdateTemplateRequest.md) |
199 | | - - [UpdateUserRequest](docs/UpdateUserRequest.md) |
200 | | - - [User](docs/User.md) |
201 | | - - [UserIdentityBody](docs/UserIdentityBody.md) |
202 | | - - [WebButton](docs/WebButton.md) |
203 | | - |
204 | | - |
205 | | -## Author |
206 | | - |
207 | | -devrel@onesignal.com |
| 93 | +## Full API reference |
| 94 | + |
| 95 | +The complete list of API endpoints and their parameters is available in the [DefaultApi documentation](https://github.com/OneSignal/onesignal-python-api/blob/main/docs/DefaultApi.md). |
208 | 96 |
|
| 97 | +For the underlying REST API, see the [OneSignal API reference](https://documentation.onesignal.com/reference). |
0 commit comments