onesignal-node-api icon indicating copy to clipboard operation
onesignal-node-api copied to clipboard

[Bug]: createNotification does not work

Open YohaanYoon opened this issue 3 years ago • 2 comments

What happened?

  • createNotification does not work.
  • I guess the reason of error is as follows:
    • https://github.com/OneSignal/onesignal-node-api/blob/bb52e8c2787f2f86a3c24459727e77f4bc960fb3/apis/DefaultApi.ts#L257
    • When I have changed from app_key to user_key, it works normally.

Steps to reproduce?

1. install 1.0.0beta9
2. setting configuration
3. run createNotification
4. not working

What did you expect to happen?

works normally, and sent push message

Relevant log output

{"errors":["Please include a case-sensitive header of Authorization: Basic <YOUR-REST-API-KEY-HERE> or Bearer token=\"<YOUR-REST-API-KEY-HERE>\" with a valid REST API key."]}
Headers: {"access-control-allow-headers":"SDK-Version","access-control-allow-origin":"*","alt-svc":"h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400","cache-control":"no-cache","cf-cache-status":"DYNAMIC","cf-ray":"78c4f54cec66a7e3-ICN","connection":"close","content-type":"application/json; charset=utf-8","date":"Fri, 20 Jan 2023 04:10:03 GMT","referrer-policy":"strict-origin-when-cross-origin","server":"cloudflare","status":"400 Bad Request","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":"b0fc6853-25f3-4ea5-92f7-2ecd96f711eb","x-runtime":"0.005988","x-xss-protection":"1; mode=block"}
    at new ApiException (/Users/yohaanyoon/classting/classting-push-service/node_modules/@onesignal/node-onesignal/dist/apis/exception.js:22:28)
    at DefaultApiResponseProcessor.<anonymous> (/Users/yohaanyoon/classting/classting-push-service/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:1707:31)
    at step (/Users/yohaanyoon/classting/classting-push-service/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:48:23)
    at Object.next (/Users/yohaanyoon/classting/classting-push-service/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:29:53)
    at fulfilled (/Users/yohaanyoon/classting/classting-push-service/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:20:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 400,
  body: BadRequestError {
    errors: [
      'Please include a case-sensitive header of Authorization: Basic <YOUR-REST-API-KEY-HERE> or Bearer token="<YOUR-REST-API-KEY-HERE>" with a valid REST API key.'
    ]
  },
  headers: {
    'access-control-allow-headers': 'SDK-Version',
    'access-control-allow-origin': '*',
    'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400',
    'cache-control': 'no-cache',
    'cf-cache-status': 'DYNAMIC',
    'cf-ray': '78c4f54cec66a7e3-ICN',
    connection: 'close',
    'content-type': 'application/json; charset=utf-8',
    date: 'Fri, 20 Jan 2023 04:10:03 GMT',
    'referrer-policy': 'strict-origin-when-cross-origin',
    server: 'cloudflare',
    status: '400 Bad Request',
    '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': 'b0fc6853-25f3-4ea5-92f7-2ecd96f711eb',
    'x-runtime': '0.005988',
    'x-xss-protection': '1; mode=block'
  }
}

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

YohaanYoon avatar Jan 20 '23 04:01 YohaanYoon

@YohaanYoon, can you clarify if this is an issue with creating notifications or if it was more of a user error due to incorrect authentication? I'm running into an issue where this function actually doesn't work regardless if authentication is correct.

iAmWillShepherd avatar Apr 05 '23 15:04 iAmWillShepherd

in my case, calling client.createNotification() and specifying included_segments causes this error whereas sending to specific ids through include_player_ids works well.

thank @YohaanYoon for pointing the workaround, swapping these two appKey and userKey value fixes the problem.

i am using version 2.0.0-beta1

hlhdai avatar Jun 14 '23 13:06 hlhdai