Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

- API version: 5.6.0
- Package version: 5.6.0
- API version: 5.7.0
- Package version: 5.7.0

## Requirements

Expand Down
5 changes: 4 additions & 1 deletion docs/DefaultApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Every operation requires either a **REST API Key** (App-scoped, used by ~77% of

### Error handling

When a request fails, the SDK raises `onesignal.ApiException`. The HTTP status code is `e.status` (int); the parsed error body is `e.body`. Most envelopes match `{"errors": ["..."]}` (an array of strings) but a few endpoints return `{"errors": [{"code": ..., "title": ..., "meta": {...}}]}` (an array of structured error objects — used by `POST /apps/{app_id}/users` 409 conflict, see `CreateUserConflictResponse`), `{"errors": "..."}` (string), or `{"success": False}` (no `errors` field at all). Robust error-handling code should tolerate all four shapes.
When a request fails, the SDK raises `onesignal.ApiException`. The HTTP status code is `e.status` (int); the parsed error body is `e.body`. Most envelopes match `{"errors": ["..."]}` (an array of strings) but a few endpoints return `{"errors": [{"code": ..., "title": ..., "meta": {...}}]}` (an array of structured error objects — used by `POST /apps/{app_id}/users` 409 conflict, see `CreateUserConflictResponse`), `{"errors": "..."}` (string), or `{"success": False}` (no `errors` field at all). Robust error-handling code should tolerate all four shapes. The `e.error_messages` property does this for you, normalizing every shape to a flat `list[str]` (empty when the body carries no `errors`).

### Polymorphic 200 from POST /notifications

Expand Down Expand Up @@ -743,6 +743,9 @@ with onesignal.ApiClient(configuration) as api_client:
except onesignal.ApiException as e:
print('Exception when calling DefaultApi->create_notification: %s\n' % e)
print('Status Code: %s' % e.status)
# `e.error_messages` flattens any error-envelope shape to a list[str];
# the raw body remains on `e.body`.
print('Error Messages: %s' % e.error_messages)
print('Response Body: %s' % e.body)
```

Expand Down
5 changes: 3 additions & 2 deletions onesignal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""


__version__ = "5.6.0"
__version__ = "5.7.0"

# import ApiClient
from onesignal.api_client import ApiClient
Expand All @@ -26,3 +26,4 @@
from onesignal.exceptions import ApiValueError
from onesignal.exceptions import ApiKeyError
from onesignal.exceptions import ApiException
from onesignal.errors import OneSignalErrors
2 changes: 1 addition & 1 deletion onesignal/api/default_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
6 changes: 3 additions & 3 deletions onesignal/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down Expand Up @@ -77,7 +77,7 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
self.user_agent = 'OpenAPI-Generator/5.6.0/python'
self.user_agent = 'OpenAPI-Generator/5.7.0/python'

def __enter__(self):
return self
Expand Down Expand Up @@ -142,7 +142,7 @@ def __call_api(
# header parameters
header_params = header_params or {}
header_params.update(self.default_headers)
header_params['OS-Usage-Data'] = "kind=sdk, sdk-name=onesignal-python, version=5.6.0"
header_params['OS-Usage-Data'] = "kind=sdk, sdk-name=onesignal-python, version=5.7.0"
if self.cookie:
header_params['Cookie'] = self.cookie
if header_params:
Expand Down
6 changes: 3 additions & 3 deletions onesignal/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down Expand Up @@ -399,8 +399,8 @@ def to_debug_report(self):
return "Python SDK Debug Report:\n"\
"OS: {env}\n"\
"Python Version: {pyversion}\n"\
"Version of the API: 5.6.0\n"\
"SDK Package Version: 5.6.0".\
"Version of the API: 5.7.0\n"\
"SDK Package Version: 5.7.0".\
format(env=sys.platform, pyversion=sys.version)

def get_host_settings(self):
Expand Down
28 changes: 28 additions & 0 deletions onesignal/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Generated from inputs/api/error-catalog.json. Do not edit by hand."""


class OneSignalErrors:
"""Sentinel error message strings the OneSignal API can return.

Each constant equals the literal message the server emits, so you can
test membership against the normalized list from
``ApiException.error_messages``::

if OneSignalErrors.NO_TARGETING_SPECIFIED in e.error_messages:
...

Note: 200-status sentinels such as NO_SUBSCRIBERS arrive on a
successful response (CreateNotificationSuccessResponse.errors), not via
the exception accessor — read the response's ``errors`` field for those.
"""

# HTTP 403 | retryable: no | emitted by: any API-key-authenticated endpoint (REST or Organization key) | note: Generic auth-failure message the public api.onesignal.com edge returns for any invalid or mismatched key — REST or Organization — so a single sentinel covers both. Supersedes the Rails-monolith INVALID_REST_API_KEY / INVALID_USER_AUTH_KEY strings, which the public host no longer returns verbatim. Note the double space after 'denied.'
INVALID_API_KEY = "Access denied. Please include an 'Authorization: ...' header with a valid API key (https://documentation.onesignal.com/docs/en/keys-and-ids#api-keys)."
# HTTP 400, 404 | retryable: no | emitted by: POST /notifications/{id}/history, POST /notifications/{id}/messages, GET /notifications/{id} (export) | note: Verified live 2026-06-16: GET /notifications/{bogus-uuid} returns 404 with this exact message.
NOTIFICATION_NOT_FOUND = "Notification not found"
# HTTP 200 | retryable: no | emitted by: POST /notifications | note: Returned with HTTP 200 OK (id is empty), not an error status. The flagship case for the errorMessages accessor — lets callers distinguish a sent notification from a no-op without parsing the polymorphic 200 body.
NO_SUBSCRIBERS = "All included players are not subscribed"
# HTTP 400 | retryable: no | emitted by: POST /notifications | note: Verified live 2026-06-16: a no-targeting POST /notifications returns 400 with this exact message.
NO_TARGETING_SPECIFIED = "You must include which players, segments, or tags you wish to send this notification to."
# HTTP 503 | retryable: yes | emitted by: any endpoint (pgbouncer rejection) | note: Transient DB/pgbouncer failure — the canonical retryable sentinel.
SERVICE_UNAVAILABLE = "Service temporarily unavailable"
47 changes: 46 additions & 1 deletion onesignal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""

import json


class OpenApiException(Exception):
"""The base exception class for all OpenAPIExceptions"""
Expand Down Expand Up @@ -123,6 +125,49 @@ def __str__(self):

return error_message

@property
def error_messages(self):
"""The error messages carried by the response body, normalized to a
flat ``list[str]`` regardless of which envelope shape the API returned
(``{"errors": "..."}``, ``{"errors": ["..."]}``,
``{"errors": [{"code": ..., "title": ...}]}``, or an object map such as
``{"errors": {"invalid_aliases": {...}}}``, surfaced as ``"<key>: <value>"``
entries). Returns an empty list when the body is not a recognizable error
envelope. The raw body remains available on ``self.body``.
"""
parsed = self.body
if isinstance(parsed, (str, bytes, bytearray)):
try:
parsed = json.loads(parsed)
except (ValueError, TypeError):
return []
if not isinstance(parsed, dict):
return []

errors = parsed.get("errors")
if isinstance(errors, str):
return [errors]
if isinstance(errors, list):
messages = []
for e in errors:
if isinstance(e, str):
messages.append(e)
elif isinstance(e, dict):
message = e.get("title") or e.get("code")
if message is not None:
messages.append(message)
return messages
if isinstance(errors, dict):
# Object-shaped envelopes (e.g. {"invalid_aliases": {...}}) carry data
# under arbitrary keys; surface each so it isn't silently dropped. Key
# order is unspecified, so sort for deterministic output.
messages = []
for key, value in errors.items():
rendered = value if isinstance(value, str) else json.dumps(value, separators=(",", ":"))
messages.append("{}: {}".format(key, rendered))
return sorted(messages)
return []


class NotFoundException(ApiException):

Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/api_key_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/api_key_tokens_list_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/basic_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/basic_notification_all_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/copy_template_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/create_api_key_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/create_api_key_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/create_notification_success_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/create_segment_conflict_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/create_segment_success_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/create_template_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/create_user_conflict_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/custom_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/custom_events_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/delivery_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
2 changes: 1 addition & 1 deletion onesignal/model/export_events_success_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com # noqa: E501

The version of the OpenAPI document: 5.6.0
The version of the OpenAPI document: 5.7.0
Contact: devrel@onesignal.com
Generated by: https://openapi-generator.tech
"""
Expand Down
Loading