node.jsexpressibm-watsonhttp-status-code-403visual-recognition

IBM Watson Visual Recognition (NodeJS) - Error code 403 : Forbidden: Access is denied due to invalid credentials


I am currently using Watson Visual Recognition API in the environment below but getting 403 invalid credential error. For your information I am running this on Ubuntu Server 16.04.6 LTS in VMware Workstation 15.5.1. The Node js code is from IBM Cloud webpage in below URL and I input the api key in my credentials. I already installed npm by using following command and following the guide.

npm install --save watson-developer-cloud
var VisualRecognitionV3 = require('watson-developer-cloud/visual-recognition/v3');
var fs = require('fs');

var visualRecognition = new VisualRecognitionV3({
  version: '2018-03-19',
  iam_apikey: 'Hy-N8Lxxxxxxxxxxxxxxxxxxxxxxxxxxxx'  // used api key in my credentials
});

var url= 'https://watson-developer-cloud.github.io/doc-tutorial-downloads/visual-recognition/640px-IBM_VGA_90X8941_on_PS55.jpg';

var params = {
  url: url,
};

visualRecognition.classify(params, function(err, response) {
  if (err) {
    console.log(err);
  } else {
    console.log(JSON.stringify(response, null, 2))
  }
});

When I execute the command node {filename}.js in the command line, I get the error message like below. For this error, the code is 403 and when I input the wrong API key, error code 400 appear so I don't think the error is on wrong api key.

Forbidden: Access is denied due to invalid credentials.
    at formatError (/home/byungmin/visual_recognition/node_modules/ibm-cloud-sdk                                       -core/lib/requestwrapper.js:111:17)
    at /home/byungmin/visual_recognition/node_modules/ibm-cloud-sdk-core/lib/req                                       uestwrapper.js:259:19
    at processTicksAndRejections (internal/process/task_queues.js:94:5) {
  name: 'Forbidden',
  code: 403,
  message: 'Access is denied due to invalid credentials.',
  body: '{"code":403,"error":"Forbidden"}',
  headers: {
    'content-type': 'application/json',
    'content-length': '34',
    'strict-transport-security': 'max-age=31536000; includeSubDomains;',
    'x-edgeconnect-midmile-rtt': '224',
    'x-edgeconnect-origin-mex-latency': '49',
    date: 'Fri, 21 Feb 2020 12:56:10 GMT',
    connection: 'close'
  }
}

Appreciated if you can help me find the solution to this problem.


Solution

  • Try this for lite account:

        const fs = require('fs');
        const { IamAuthenticator } = require('ibm-watson/auth');
        var VisualRecognitionV3 = require('watson-developer-cloud/visual-recognition/v3');
    
    
            var visualRecognition = new VisualRecognitionV3({
              authenticator: new IamAuthenticator({
                apikey: 'Hy-N8Lxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    
              }),
              url: 'https://watson-developer-cloud.github.io/doc-tutorial-downloads/visual-recognition/640px-IBM_VGA_90X8941_on_PS55.jpg',
            });
    
    var params = {
      url: url,
    };
    
    visualRecognition.classify(params, function(err, response) {
      if (err) {
        console.log(err);
      } else {
        console.log(JSON.stringify(response, null, 2))
      }
    });