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]: Executing getPlayer request with Identity Verification enabled is throwing an error #19

Closed
1 task done
arquadrado opened this issue Jul 12, 2022 · 5 comments
Closed
1 task done
Assignees
Labels
bug Something isn't working

Comments

@arquadrado
Copy link

arquadrado commented Jul 12, 2022

What happened?

I am using the node client to interact with OneSignal's API and I am having trouble getting players since I enabled Identity Verification. I followed this and this documentation page but I always get a 400 response.

Steps to reproduce?

Just run this snippet with valid values, in my case I am trying to get a player which has the device type equal to 11 (email):

const OneSignal = require("@onesignal/node-onesignal");
const crypto = require("crypto");

const APP_ID = "*******************************";

const app_key_provider = {
  getToken() {
    return "*****************************8";
  },
};

// configuration object
let configuration = OneSignal.createConfiguration({
  authMethods: {
    app_key: {
      tokenProvider: app_key_provider,
    },
  },
});

client = new OneSignal.DefaultApi(configuration);


const getPlayer = async (playerId, email) => {
  if (email) {
    const hmac = crypto.createHmac("sha256", app_key_provider.getToken());
    hmac.update(email);

    return await client.getPlayer(APP_ID, playerId, hmac.digest("hex"));
  }
  return await client.getPlayer(APP_ID, playerId);
};

(async function () {
await getPlayer(
    "someplayerid",
    "some-email@email.com"
  );
})();

What did you expect to happen?

I expected to receive the requested player. I am able to retrieve players without device type=email and I was printing some values inside the client code and it has the email auth hash available and builds the request with it. I am assuming it's something in the API itself and not the client.

Relevant log output

Error: HTTP-Code: 400
Message: "Unknown API Status Code!\nBody: \"[object Object]\""
    at new ApiException (/home/dev/hubspot-private-test/node_modules/@onesignal/node-onesignal/dist/apis/exception.js:20:28)
    at DefaultApiResponseProcessor.<anonymous> (/home/dev/hubspot-private-test/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:1193:31)
    at step (/home/dev/hubspot-private-test/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:46:23)
    at Object.next (/home/dev/hubspot-private-test/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:27:53)
    at /home/dev/hubspot-private-test/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:21:71
    at new Promise (<anonymous>)
    at __awaiter (/home/dev/hubspot-private-test/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:17:12)
    at DefaultApiResponseProcessor.getPlayer (/home/dev/hubspot-private-test/node_modules/@onesignal/node-onesignal/dist/apis/DefaultApi.js:1170:16)
    at /home/dev/hubspot-private-test/node_modules/@onesignal/node-onesignal/dist/types/ObservableAPI.js:370:113
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 400,
  body: 'Unknown API Status Code!\nBody: "[object Object]"'
}

Code of Conduct

  • I agree to follow this project's Code of Conduct
@arquadrado arquadrado added the bug Something isn't working label Jul 12, 2022
@jkasten2
Copy link
Member

@arquadrado Thanks for reporting this issue. We will look into reproducing the issued based on the details you provided.

@kesheshyan kesheshyan self-assigned this Jul 27, 2022
@kesheshyan
Copy link
Contributor

kesheshyan commented Oct 31, 2022

Hey @arquadrado , sorry for the delay. We are about to release updated version of our library. I will update this issue when its done.

@kesheshyan
Copy link
Contributor

Hey @arquadrado
We just updated the NPM package for our Node library
https://www.npmjs.com/package/@onesignal/node-onesignal

Please let us know if the issue still persists.

@emdrayallday
Copy link

@kesheshyan

I'm receiving a similar error using "@onesignal/node-onesignal": "^1.0.0-beta7",

  const oneSignalConfig = OneSignal.createConfiguration({
    userKey: ***,
    appKey:  **

    // authMethods: {
    //   user_key: {
    //     tokenProvider: {
    //       getToken() {
    //         return '****'
    //       }
    //     }
    //   },
    //   app_key: {
    //     tokenProvider: {
    //       getToken() {
    //         return '***'
    //       }
    //     }
    //   }
    // }
  })

  const oneSignalClient = new OneSignal.DefaultApi(oneSignalConfig)
  oneSignalClient.getPlayers('app_id') <---- this fails with
"ok": false,
"message": "HTTP-Code: 400\nMessage: Unknown API Status Code!\nBody: {}\nHeaders: {\"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\":\"7799252b1972b70f-JAX\",\"connection\":\"close\",\"content-encoding\":\"gzip\",\"content-type\":\"application/json; charset=utf-8\",\"date\":\"Wed, 14 Dec 2022 18:53:56 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, Accept-Encoding\",\"via\":\"1.1 google\",\"x-content-type-options\":\"nosniff\",\"x-download-options\":\"noopen\",\"x-envoy-upstream-service-time\":\"6\",\"x-frame-options\":\"SAMEORIGIN\",\"x-permitted-cross-domain-policies\":\"none\",\"x-request-id\":\"e69a90ec-477b-4cd2-a28d-09b32fefb6a1\",\"x-runtime\":\"0.005469\",\"x-xss-protection\":\"1; mode=block\"}"
}

@nan-li
Copy link
Contributor

nan-li commented May 9, 2024

Closing as outdated. 400s have been added to all responses for a while now.

@nan-li nan-li closed this as completed May 9, 2024
@nan-li nan-li mentioned this issue May 9, 2024
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

5 participants