OneSignal / onesignal-node-api

OneSignal Node Client
Other
30 stars 17 forks source link

[question]: Having problems making a simple fetchUser API call + broken links in docs #68

Open kpturner opened 1 year ago

kpturner commented 1 year ago

How can we help?

I cannot seem to make a simple fetchUser API call work. The documentation tells me to do it like so:

const configuration = OneSignal.createConfiguration({
  userKey: process.env.ONESIGNAL_USER_KEY
  appKey: process.env.ONESIGNAL_APP_ID,
})

const client = new OneSignal.DefaultApi(configuration)

client
  .fetchUser('my_app_id', 'external_id', 'foo')
  .then((data) => {
    logger.debug(data, 'API called successfully. Returned data')
  })
  .catch((error) => logger.error(error, 'Error calling OneSignal'))

It is not totally clear what the userKey and appKey should be so I have assumed that this is the application key and REST API key from the "Keys & IDs" page on the OneSignal Dashboard.

However, when I try that I just get

Error: HTTP-Code: 404
    Message: Unknown API Status Code!
    Body: {}

I saw other issues logged where people have set the configuration like this:

const appKeyProvider = {
  getToken() {
    return process.env.ONESIGNAL_REST_API_KEY as string
  },
}
const configuration = OneSignal.createConfiguration({
  authMethods: {
    app_key: {
      tokenProvider: appKeyProvider,
    },
  },
})

But that just gives me the same error.

I then found this: https://github.com/OneSignal/onesignal-node-api/blob/main/DefaultApi.md#fetchUser

But that does not work because fetchUser expects 3 (or 4) parameter, not 1.

What am I doing wrong?

As an aside, this https://github.com/OneSignal/onesignal-node-api has broken or misleading links.

The link here does not take you to anywhere useful image

And this link is broken image

Code of Conduct

kpturner commented 1 year ago

Well I finally got it working by providing no configuration at all

const configuration = OneSignal.createConfiguration({})
const client = new OneSignal.DefaultApi(configuration)
client
  .fetchUser(process.env.ONESIGNAL_APP_ID as string, 'external_id', 'foo')
  .then((data) => {
    logger.debug(data, 'API called successfully. Returned data')
  })
  .catch((error) => logger.error(error, 'Error calling OneSignal'))