0
votes

I created a simple program for testing. I just wanted to ping the Watson Discovery server for Env details (https://www.ibm.com/watson/developercloud/discovery/api/v1/?node#list_environment_details).

const dotenv = require( 'dotenv');
dotenv.config()
const DiscoveryV1 = require('watson-developer-cloud/discovery/v1');

  var discovery = new DiscoveryV1({
    username: process.env.USERNAME,
    password: process.env.PASSWORD,
    version_date: '2017-11-07'
  });

discovery.getEnvironments({}, function(error, data) {
  console.log('Env:', JSON.stringify(data, null, 2));//returns data
   //doesn't appear to be called
  discovery.getEnvironment({ environment_id: process.env.ENVIRONMENT}), function(error, data) {
    if (error){
      console.log('Env Details', JSON.stringify(error, null, 2));    
    }
    console.log('Env Details', JSON.stringify(data, null, 2));
  };
});

the result node index.js

  Env: {
      "environments": [
        {
          "environment_id": "system",
          "name": "Watson System Environment",
          "description": "Shared system data sources",
          "read_only": true
        },
        {
          "environment_id": "my value",
          "name": "byod",
          "description": "",
          "created": "2018-01-24T14:52:47.736Z",
          "updated": "2018-01-24T14:52:47.736Z",
          "read_only": false
        }
      ] 
    }

I can get it to work with a curl command, so I know I have the right information. It is just the node calls.

 curl -u "{username}":"{pw}" "https://gateway.watsonplatform.net/discovery/api/v1/environments/my value?version=2017-11-07"
1
May you edit with your curl command? - Sayuri Mizuguchi

1 Answers

0
votes

The only way I could get it to work was with using curl in node.

var options = {
url: 'https://gateway.watsonplatform.net/discovery/api/v1/',
auth: {
    'user': process.env.WATSON_DISCOVERY_USERNAME,
    'pass': process.env.WATSON_DISCOVERY_PASSWORD
}
};

  request(options, function(error, response, body){
if (!error && response.statusCode == 200) {
    //console.log('from made callback', body);
      res.json({
        "input" : req.body.input.text,
        response : body});
}
});