The updateDocument api in the Discovery module of ibm's watson-developer-cloud Node.js sdk insists on a file parameter

495 views Asked by At

I am trying to insert/update documents in IBM's Discovery service via the watson-developer-cloud Node.js SDK, and it's not working. Some of my documents don't have an associated file, so they are metadata-only. This documentation says that You must provide document content, metadata, or both. However, the updateDocument call fails if you try to update a metadata-only document.

I tracked down the problem to line 607 in node-sdk/discovery/v1.js which is requiredParams: ['environment_id', 'collection_id', 'document_id', 'file'] and I believe that is the source of the problem, as it indicates that 'file' is a required parameter, contrary to what the API documentation states. The API documentation must be correct, because I can update a metadata-only document just fine from the Discovery API explorer.

1

There are 1 answers

3
German Attanasio On

You just need to make sure you call updateJsonDocument() and send an empty object

const DiscoveryV1 = require('watson-developer-cloud/discovery/v1');
const fs = require('fs');

const discovery = new DiscoveryV1({
  username: 'YOUR USERNAME',
  password: 'YOUR PASSWORD',
  version_date: DiscoveryV1.VERSION_DATE_2017_08_01
});

discovery.updateJsonDocument(
  {
    environment_id: 'YOUR ENVIRONMENT ID',
    collection_id: 'YOUR COLLECTION ID',
    configuration_id: 'YOUR CONFIGURATION ID',
    file: {},
    metadata: { foo: 'bar' }
  },
  function(error, data) {
    if (error) {
      console.log(error);
    } else {
      console.log(data);
    }
  }
);

The documentation is not updated but you can see the method here.