OneSignal / onesignal-python-api

Other
15 stars 6 forks source link

Not showing in OneSignal Dashboard #25

Open ZeelChauhanHtree opened 11 months ago

ZeelChauhanHtree commented 11 months ago

How can we help?

def send_notification(title, content, send_after):
    # try:
    #     one_signal_client = set_client()
    #     response = one_signal_client.create_(notification_body)
    #     return response
    # except Exception as e:
    #     print("Failed Notification")
    #     return e
    configuration = set_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=ONE_SIGNAL_APP_ID,
            channel_for_external_user_ids='push',
            headings={"en": title},
            contents={"en": content},
            send_after=send_after,
            included_segments=["All"],
            is_chrome_web=True,
        )

        # example passing only required values which don't have defaults set
        try:
            # Create notification
            response = api_instance.create_notification(
                notification, _check_return_type=True)

            # ********************************** different way
            # import requests

            # url = "https://onesignal.com/api/v1/notifications"

            # payload = {
            #     "app_id": ONE_SIGNAL_APP_ID,
            #     "included_segments": ["Subscribed Users"],
            #     "contents": {
            #         "en": "English or Any Language Message",
            #         "es": "Spanish Message"
            #     },
            #     "name": "INTERNAL_CAMPAIGN_NAME"
            # }
            # headers = {
            #     "accept": "application/json",
            #     "Authorization": "Basic "+ONE_SIGNAL_USER_AUTH_KEY,
            #     "Content-Type": "application/json",
            # }

            # response = requests.post(url, json=payload, headers=headers)

            # print(response.text)

            # **********************************
            return response
        except onesignal.ApiException as e:
            print("Exception when calling DefaultApi->create_notification: %s\n" % e)

When hitting the create_notification not showing in OneSignal Dashboard

Code of Conduct