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
4 changes: 2 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 Down
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
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
2 changes: 1 addition & 1 deletion onesignal/model/export_subscriptions_request_body.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_subscriptions_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/filter.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