Skip to content
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

[Bug]: CAn't create notification using include_subscription_ids #67

Closed
1 task done
bensebborn opened this issue Aug 19, 2023 · 8 comments
Closed
1 task done

[Bug]: CAn't create notification using include_subscription_ids #67

bensebborn opened this issue Aug 19, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@bensebborn
Copy link

What happened?

Sending notification using "included_segments" works, however swapping this to use "include_subscription_ids" fails with a 400 error with no meaningful error message


const app_key_provider = {
    getToken() {
        return process.env.ONESIGNAL_APP_KEY;
    }
};
const configuration = OneSignal.createConfiguration({
    authMethods: {
        app_key: {
            tokenProvider: app_key_provider
        }
    }
});

const client = new OneSignal.DefaultApi(configuration);

    const notification = new OneSignal.Notification();

    notification.app_id = ONESIGNAL_APP_ID;
    //notification.included_segments = ['XXXXXXX'];
    notification.include_player_ids = ['XXX-XXX-XXX-XXX'];
    notification.contents = {
        en: "Hello OneSignal!"
    };
    notification.headings = {
        en: "Title"
    };
    
    const oneSignalInfo = await client.createNotification(notification);

Steps to reproduce?

Run the above code with included_segments enabled - works
Run the above code with include_player_ids - fails

Have also tried swapping 'include_player_ids' with 'include_subscription_ids' but same error.

What did you expect to happen?

Notification sent

Relevant log output

{"errorType":"Error","errorMessage":"HTTP-Code: 400\nMessage: Bad Request\nBody: {\"errors\":[{}]}\nHeaders: {\"access-control-allow-headers\":\"SDK-Version\",\"access-control-allow-origin\":\"*\",\"alt-svc\":\"h3=\\\":443\\\"; ma=86400\",\"cache-control\":\"no-cache\",\"cf-cache-status\":\"DYNAMIC\",\"cf-ray\":\"7f93f5078fe934d7-DUB\",\"connection\":\"close\",\"content-type\":\"application/json; charset=utf-8\",\"date\":\"Sat, 19 Aug 2023 17:01:12 GMT\",\"referrer-policy\":\"strict-origin-when-cross-origin\",\"server\":\"cloudflare\",\"set-cookie\":\"__cf_bm=X; path=/; expires=Sat, 19-Aug-23 17:31:12 GMT; domain=.onesignal.com; HttpOnly; Secure; SameSite=None\",\"strict-transport-security\":\"max-age=15552000; includeSubDomains\",\"transfer-encoding\":\"chunked\",\"vary\":\"Origin\",\"via\":\"1.1 google\",\"x-content-type-options\":\"nosniff\",\"x-download-options\":\"noopen\",\"x-frame-options\":\"SAMEORIGIN\",\"x-permitted-cross-domain-policies\":\"none\",\"x-request-id\":\"8d36b0e2-49f1-42d7-8891-a1d4812afe9d\",\"x-runtime\":\"0.009648\",\"x-xss-protection\":\"1; mode=block\"}","code":400,"body":{"errors":[{}]},"headers":{"access-control-allow-headers":"SDK-Version","access-control-allow-origin":"*","alt-svc":"h3=\":443\"; ma=86400","cache-control":"no-cache","cf-cache-status":"DYNAMIC","cf-ray":"7f93f5078fe934d7-DUB","connection":"close","content-type":"application/json; charset=utf-8","date":"Sat, 19 Aug 2023 17:01:12 GMT","referrer-policy":"strict-origin-when-cross-origin","server":"cloudflare","set-cookie":"X=; path=/; expires=Sat, 19-Aug-23 17:31:12 GMT; domain=.onesignal.com; HttpOnly; Secure; SameSite=None","strict-transport-security":"max-age=15552000; includeSubDomains","transfer-encoding":"chunked","vary":"Origin","via":"1.1 google","x-content-type-options":"nosniff","x-download-options":"noopen","x-frame-options":"SAMEORIGIN","x-permitted-cross-domain-policies":"none","x-request-id":"8d36b0e2-49f1-42d7-8891-a1d4812afe9d","x-runtime":"0.009648","x-xss-protection":"1; mode=block"},"stack":["Error: HTTP-Code: 400","Message: Bad Request","Body: {\"errors\":[{}]}","Headers: {\"access-control-allow-headers\":\"SDK-Version\",\"access-control-allow-origin\":\"*\",\"alt-svc\":\"h3=\\\":443\\\"; ma=86400\",\"cache-control\":\"no-cache\",\"cf-cache-status\":\"DYNAMIC\",\"cf-ray\":\"7f93f5078fe934d7-DUB\",\"connection\":\"close\",\"content-type\":\"application/json; charset=utf-8\",\"date\":\"Sat, 19 Aug 2023 17:01:12 GMT\",\"referrer-policy\":\"strict-origin-when-cross-origin\",\"server\":\"cloudflare\",\"set-cookie\":\"X; path=/; expires=Sat, 19-Aug-23 17:31:12 GMT; domain=.onesignal.com; HttpOnly; Secure; SameSite=None\",\"strict-transport-security\":\"max-age=15552000; includeSubDomains\",\"transfer-encoding\":\"chunked\",\"vary\":\"Origin\",\"via\":\"1.1 google\",\"x-content-type-options\":\"nosniff\",\"x-download-options\":\"noopen\",\"x-frame-options\":\"SAMEORIGIN\",\"x-permitted-cross-domain-policies\":\"none\",\"x-request-id\":\"8d36b0e2-49f1-42d7-8891-a1d4812afe9d\",\"x-runtime\":\"0.009648\",\"x-xss-protection\":\"1; mode=block\"}"," at new ApiException (/var/task/node_modules/@onesignal/node-onesignal/dist/apis/exception.js:22:28)"," at DefaultApiResponseProcessor.<anonymous> (/var/task/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:1770:31)"," at step (/var/task/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:48:23)"," at Object.next (/var/task/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:29:53)"," at fulfilled (/var/task/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:20:58)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"]}

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bensebborn bensebborn added the bug Something isn't working label Aug 19, 2023
@kesheshyan
Copy link
Contributor

kesheshyan commented Aug 22, 2023

Hey @bensebborn. Thanks for reaching out, we are sorry that you are having problems with this SDK.

Do you use the latest version 2.0.1-beta2? We recently added 400 error handlers to all our endpoints

While it may not fix the problem, it should at least show the error coming from the server.

I'll create an internal ticket to investigate this problem.

Meanwhile, if you are blocked by this issue you can always use this endpoints manually, making any type of HTTP requests (CURL, java script fetch etc.) https://documentation.onesignal.com/reference/create-notification

@bensebborn
Copy link
Author

Hi there,

Thanks for the reply :)

I noticed in the commits that the error handler had been removed from -beta2.

I've just downgraded to -beta1 and I can now see the correct error message. Thanks!

@kpturner
Copy link

kpturner commented Aug 31, 2023

Do you use the latest version 2.0.1-beta2? We recently added 400 error handlers to all our endpoints

While it may not fix the problem, it should at least show the error coming from the server.

I don't understand that reply. Are you saying that using 2.0.1-beta2 helps diagnose the problem because it has added error handlers? I am not finding that to be the case using that version. I am trying a simple notification using a template and I just get

✖ Error: HTTP-Code: 400
  Message: Bad Request
  Body: {"errors":[{}]}

@bensebborn says he downgraded to get a useful error message? Is that the expected approach?

I am trying something very simple:

  const notification = new OneSignal.Notification()
notification.app_id = appId
notification.template_id = 'redacted'
notification.custom_data = {
  ...redacted
}
notification.include_external_user_ids = ['redacted'] // This is deprecated but
// include_aliases: { onesignal_id: [redacted'] }, // the recommended approach is not possible
await client.createNotification(notification)

@kpturner
Copy link

kpturner commented Sep 1, 2023

Pinning to version 2.0.1-beta1 meant I was able to get meaningful error messages again.

I find this worrying given that I am evaluating OneSignal with a view to purchasing a licence. It seems that this particular SDK is not keeping up with the API - and is breaking fundamental things with new releases? :(

@MathieuPierfitte
Copy link

Same here, I had to downgrade to 2.0.1-beta1 otherwise the response body would just be r { errors: [ r {}, r {}, r {} ] }.

@novelle-group
Copy link

novelle-group commented Feb 10, 2024

It's crazy that this has still not been sorted. Frustrated me all night until I came here to see this

@kpturner
Copy link

It's been recommended to me (by OneSignal) to use the REST API directly using any http client and to not use this particular SDK

@sherwinski
Copy link

Hi, we have had no further reports of this. Please upgrade the OneSignal SDK if you or anyone is still having this issue. If this is still an issue, please open a new report with updated information and we will investigate. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants