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

Visual Recognition doesn't recognize IAM_APIKEY and URL from credentials.env provided by the service. #1004

Closed kyokonishito closed 4 years ago

kyokonishito commented 4 years ago

Overview Visual Recognition doesn't recognize IAM_APIKEY and URL from credentials.env provided by the service. When I put the credentials.env provided by the visual recognition service to the working directory, the api returns 'Error: Missing required parameters: apikey'.

Expected behavior The apikey is loaded from credentials.env.

Actual behavior the api returns 'Error: Missing required parameters: apikey'.

How to reproduce

  1. Download credentials.env to the working directory of #2 code from Visual Recognition service.
  2. Run following code with node.js
var VisualRecognitionV3 = require('ibm-watson/visual-recognition/v3'); 
var visualRecognition = new VisualRecognitionV3({ 
  version: '2018-05-01'
});

Screenshots If applicable, add screenshots to help explain your problem.

SDK Version v5.2.0

Additional information: The SDK only reads the variables started from WATSON_VISIONCOMBINED. However the values of credentials.env are started from VISUALRECOGNITION. SDK v4 reads both values.

salimbene commented 4 years ago

You need to pass it to the constructor:

var visualRecognition = new VisualRecognitionV3({ 
  version: '2018-05-01',
  apikey: 'YOU_IAM_API_KEY_VARIABLE'
});
kyokonishito commented 4 years ago

My issue is the sdk does not read the api key from the credentials.env provided by the service explained as README.md, not how to pass the APIKEY.

germanattanasio commented 4 years ago

This is a known issue and we are working on the fix.

The SDK will recognize VISUAL_RECOGNITION_ which is the one that in the credentials file.

In the meantime can you use the snippet from @msalimbe1?

const visualRecognition = new VisualRecognitionV3({ 
 version: '2018-05-01',
 apikey: process.env.VISUAL_RECOGNITION_IAM_APIKEY
});
germanattanasio commented 4 years ago

Related to https://github.com/watson-developer-cloud/node-sdk/issues/994

kyokonishito commented 4 years ago

@germanattanasio Thank you! I will pass the api key as your code until getting the fix.

tanushreepaul04 commented 4 years ago

The same issue is there with Watson Assistant. Not reading from ibm-credential.env file. If IAM credential is given in a ibm-credential.env file, AsistantV2 can not read it from that ".env" Always throwing Error: Missing required parameters: apikey. It only works if the credentials are passed in constructor directly. Used a work around: Using a json file say "watson-config.json" to store credential, then reading it using a small node module "read-search-json". (its my own contribution https://www.npmjs.com/package/read-search-json) A node module to read and search out JSON data from an input JSON file('*.json'). Inputs are the JSON file path and a Search Path constructed as a string array of Keys. Sample "watson-config.json" :

{
    "watson-assistant-config": {
        "apikey": "the-api-key",
        "url": "the-url"
    }
}

Sample Call : (assuming the "watson-config.json" in in the same folder from where "node" is running

const AssistantV2 = require('ibm-watson/assistant/v2');
const readjson = require('read-search-json');
readjson.readJSON("./watson-config.json", ["watson-assistant-config"], function (data, err) {
        if (data) {
              console.log(data);
            var assistant = new AssistantV2(data);
            // start Watson Assistant Session
        }
        if (err)
            console.log(err);
    });
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

@tanushreepaul04 Can you please show us the keys in the ibm-credentials.env file? I think it's related to the keys not being the ones that the SDK is looking for

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.