I'm using IBM Cloud functions
for requesting some results from IBM Watson Discovery
. There is a very good GitHub repo here about how can we invoke this. However, on the way of setting the action in the function an error with message Cannot find module 'ibm-watson/auth' occurs. I understand what the message says, but if you check the GitHub repo, you see that I apply exactly the same steps. My IBM Cloud function code is:
case 'doc_info':
var user_input = params.user_input;
const watson = require('ibm-watson/sdk');
const { CloudantV1 } = require('@cloudant/cloudant');
const DiscoveryV1 = require('ibm-watson/discovery/v1');
const { IamAuthenticator } = require('ibm-watson/auth');
//const { IamAuthenticator } = require('ibm-cloud-sdk-core');
try {
const discovery = new DiscoveryV1({ // Initializing Discovery
version: '2020-11-24',
authenticator: new IamAuthenticator({
apikey: params.apiKeyDisco,
}),
serviceUrl: params.urlDisco,
});
const cloudant = new CloudantV1({ // Initializing CloudantV1
authenticator: new IamAuthenticator({
apikey: params.apiKeyCloudant
})
});
cloudant.setServiceUrl(params.urlCloudant);
// ...
return {
answer: "Simple test"
};
} catch (err) {
console.log(err)
return Promise.reject({
statusCode: 500,
headers: { 'Content-Type': 'application/json' },
body: { message: err.message },
});
}
break;
I've tried even with calling IamAuthenticator
from the ibm-cloud-sdk-core package, but then the error is IamAuthenticator is not a constructor. How can we solve this?