Skip to content

Complete example to send a notification #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,45 @@ sudo python setup.py install
Please follow the [installation procedure](#installation--usage) and then run the following:

```python

from pprint import pprint

import onesignal
from onesignal.api import default_api
from onesignal.model.filter import Filter
from onesignal.model.notification import Notification

APP_ID = "YOUR_ONE_SIGNAL_APP_ID"

# See configuration.py for a list of all supported configuration parameters.
# Some of the OneSignal endpoints require USER_KEY bearer token for authorization as long as others require APP_KEY
# (also knows as REST_API_KEY). We recommend adding both of them in the configuration page so that you will not need
# to figure it yourself.
configuration = onesignal.Configuration(
app_key = "YOUR_APP_KEY",
user_key = "YOUR_USER_KEY"
app_key=REST_API_KEY, # also knows as REST_API_KEY
user_key=USER_KEY
)


# Enter a context with an instance of the API client
with onesignal.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = default_api.DefaultApi(api_client)

notification = Notification(
app_id=APP_ID,
contents={"en": "This is the content for English"},
headings={"en": "This is the title for English"},

# We want to reach all users having OSVersion at 16.6
filters=[Filter(field="tag", key="OSVersion", relation="=", value="16.6")],
)

try:
# Create notification
api_response = api_instance.create_notification(notification)
pprint(api_response)
except onesignal.ApiException as e:
print("Exception when calling DefaultApi->create_notification: %s\n" % e)

```

## Documentation for API Endpoints
Expand Down