watson-developer-cloud / node-sdk

:comet: Node.js library to access IBM Watson services.
https://www.npmjs.com/package/ibm-watson
Apache License 2.0
1.48k stars 670 forks source link

Node.js code not working from the API docs #980

Closed upkarlidder closed 4 years ago

upkarlidder commented 4 years ago

Overview The code for Node.js from the API docs does not work.

const visualRecognition = new VisualRecognitionV3({
  version: '2018-03-19',
  iam_apikey:  vrKey
});

I get the following error:

Error: Missing required parameters: apikey
    at Object.getMissingParams (/Users/ulidder/Documents/icloud-documents/code-upkar/att5g/vr/node_modules/ibm-cloud-sdk-core/lib/helper.js:101:11)
    at Object.validateInput (/Users/ulidder/Documents/icloud-documents/code-upkar/att5g/vr/node_modules/ibm-cloud-sdk-core/auth/utils/helpers.js:61:39)
    at new IamAuthenticator (/Users/ulidder/Documents/icloud-documents/code-upkar/att5g/vr/node_modules/ibm-cloud-sdk-core/auth/authenticators/iam-authenticator.js:47:17)

Expected behavior Expected the code in API docs to work without throwing the error. I got it working with the following code

const visualRecognition = new VisualRecognitionV3({
  version: '2018-03-19',
  authenticator: new IamAuthenticator({ apikey: vrKey }),
});

Actual behavior Get error

Error: Missing required parameters: apikey
    at Object.getMissingParams (/Users/ulidder/Documents/icloud-documents/code-upkar/att5g/vr/node_modules/ibm-cloud-sdk-core/lib/helper.js:101:11)
    at Object.validateInput (/Users/ulidder/Documents/icloud-documents/code-upkar/att5g/vr/node_modules/ibm-cloud-sdk-core/auth/utils/helpers.js:61:39)
    at new IamAuthenticator (/Users/ulidder/Documents/icloud-documents/code-upkar/att5g/vr/node_modules/ibm-cloud-sdk-core/auth/authenticators/iam-authenticator.js:47:17)

How to reproduce Copy paste the code from the Node.js API docs.

Screenshots N/A

SDK Version const VisualRecognitionV3 = require('ibm-watson/visual-recognition/v3');

Additional information: Node version v11.14.0

Additional context Ran into this error at a hackathon. The Python code works as it is. Node.js does not.

SirSpidey commented 4 years ago

You've caught us in between releasing the SDK major version and updating the docs. For now, take a look at the example at https://github.com/watson-developer-cloud/node-sdk/blob/master/README.md#visual-recognition that shoes the authentication

hgw2101 commented 4 years ago

For reference, the affected Node version here is 8.10.

upkarlidder commented 4 years ago

@SirSpidey, that is what I ended up doing. But I don't think other people make that connection and unfortunately just give up on the service. I am an IBMer at a hackathon. I expected the code example in the official API docs to work without having to dig into the SDK source :(. It is also concerning that the examples between API docs and the SDK Github docs are different. Thank you for your attention to this.

mkistler commented 4 years ago

@SirSpidey This is a bug in the front matter for the Node SDK in that it does not specify the version of the Node SDK -- unlike all the other languages. We need to update the Node front-matter to change:

npm install ibm-watson

to something like:

npm install ibm-watson@^4.0.0

While we're at it, we should throw in '--save', so that it adds the dependency to the application's package.json. So I recommend that the front-matter update for the new major release should be

npm install --save ibm-watson@^5.0.0
MasterOdin commented 4 years ago

While we're at it, we should throw in '--save', so that it adds the dependency to the application's package.json

Since NPM 5, that's the default behavior unless specified otherwise via flags or editing your .npmrc.

SirSpidey commented 4 years ago

@mkistler Got it. Will update the front matter for the install command. Yes, we just removed the --save option.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

germanattanasio commented 4 years ago

@SirSpidey was this fixed?

SirSpidey commented 4 years ago

Yes. install is now in this format npm install ibm-watson@^5.2.0.