OneSignal / onesignal-node-api

OneSignal Node Client
Other
30 stars 17 forks source link

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

Open bensebborn opened 1 year ago

bensebborn commented 1 year ago

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

kesheshyan commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 10 months ago

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 commented 7 months ago

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

kpturner commented 7 months ago

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