OneSignal / onesignal-python-api

Other
12 stars 6 forks source link

[Bug]: Your SDK does not work #13

Closed lifenautjoe closed 1 year ago

lifenautjoe commented 1 year ago

What happened?

I've followed all your steps and after 4 hours of frustration, I decided to use another push notification service.

Steps to reproduce?

Run

app_key = settings.ONE_SIGNAL_APP_ID
api_key = settings.ONE_SIGNAL_REST_API_KEY
user_key = settings.ONE_SIGNAL_USER_AUTH_KEY

configuration = onesignal.Configuration(
    app_key = app_key,
    api_key = api_key,
    user_key = user_key
)

def send_notification(notification):
    with onesignal.ApiClient(configuration) as api_client:
        # Create an instance of the API class
        api_instance = default_api.DefaultApi(api_client)    

        notification.set_attribute('app_id', app_key)        

        return api_instance.create_notification(notification)

Where notification is a properly formed `Notification` object

What did you expect to happen?

My simple notification would be sent, yet I get

 Status Code: 400
retrato-worker     | Reason: Bad Request
retrato-worker     | HTTP response headers: HTTPHeaderDict({'Date': 'Wed, 28 Dec 2022 16:32:19 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'status': '400 Bad Request', 'cache-control': 'no-cache', 'access-control-allow-origin': '*', 'vary': 'Accept, Origin, Accept-Encoding', 'referrer-policy': 'strict-origin-when-cross-origin', 'x-permitted-cross-domain-policies': 'none', 'x-xss-protection': '1; mode=block', 'x-request-id': 'f9eb290f-e7ff-4446-8c12-8037849f01cc', 'access-control-allow-headers': 'SDK-Version', 'x-download-options': 'noopen', 'x-runtime': '0.006261', 'x-frame-options': 'SAMEORIGIN', 'x-content-type-options': 'nosniff', 'x-envoy-upstream-service-time': '8', 'Via': '1.1 google', 'Alt-Svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400', 'CF-Cache-Status': 'DYNAMIC', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'Server': 'cloudflare', 'CF-RAY': '780bb0f6b88803fa-LIS'})
retrato-worker     | HTTP response body: {"errors":["Please include a case-sensitive header of Authorization: Basic \u003cYOUR-REST-API-KEY-HERE\u003e or Bearer token=\"\u003cYOUR-REST-API-KEY-HERE\u003e\" with a valid REST API key."],"reference":["https://documentation.onesignal.com/docs/accounts-and-keys#section-keys-ids"]}

I've made sure I'm doing everything exactly as per your documentation, I've tried everything on my end, but it seems that either your API is broken, or your SDK is.

In terms of your docs, they're also so overly complex.

People come looking for "How to send X notification to Y" not to get 100 classes definitions.

Sorry if I sound mean but I am quite annoyed at wasting an entire work day on this.

Relevant log output

No response

Code of Conduct

Edit

My API keys are not wrong.

In the end I just did the create notification call using requests and everything worked as expected.

I'm convinced your sdk is broken.

kesheshyan commented 1 year ago

Hey @lifenautjoe . We are really sorry to hear your experience with our library was so frustrating. This library and the documentation is generated by the OpenAPI generator. From the code you provided I think I can see the problem. In the documentation there is an example of how to properly setup Configuration object:

configuration = onesignal.Configuration(
    app_key = "YOUR_APP_KEY",
    user_key = "YOUR_USER_KEY"
)

It's only includes app_key and user_key, there is no api_key though. Some of our endpoints require app level authorization and some require user level authorization. In the code you provided you setting up the app_key as an APP_ID, which is incorrect, it should be the APP_KEY_TOKEN.

Just in case here is how you can get those keys:

I sincerely hope this will help fix your issue. Please feel free to reopen this issue if you still have this problem.