Search code examples
node.jsibm-cloudwatson-conversation

Watson Conversation API says: 'Patterns are defined but type is not specified.'


I am trying to call the updateValue method of the Watson Conversation API using the Watson SDK for Node.js. The request updates the patterns of the patterns-type entity value.

My request fails with a 400 Bad Request and the message:

[ { message: 'Patterns are defined but type is not specified.',
       path: '.patterns' } ],

Here is the code I'm using to call the API - pretty standard.:

      let params = {
        workspace_id: '<redacted>',
        entity: 'myEntityType',
        type: 'patterns', // tried with and without this line
        value: 'myCanonicalValue',
        new_patterns: ['test'],
      };

      watsonApi.updateValue(params, (error, response) => {
        if (error) {
          console.log('Error returned by Watson when updating an entity value.');
          reject(error);
        } else {
          resolve(response);
        }
      });

Actually, what the request is doing is trying to delete a pattern from the pattern list. Since there is no endpoint for deleting patterns, I fetch the list of patterns, delete the one I need to delete from the pattern list, and send the now-reduced patterns list via the updateValue method. In the above example, imagine the pattern list was ['test', 'test2']. By calling updateValue with ['test'] only, we are deleting the test2 pattern.

I am using a previous API version but I've also tested it in the Assistant API Explorer and the version 2018-07-10 results in the same problem when sending a raw request body formed as follows:

{
  "patterns": ["test"]
}

Am I doing something wrong or did I forget a parameter?


Solution

  • It's not a bug, but it is a non-intuitive parameter name. The service accepts a type parameter and the Node SDK has a wrapper parameter called new_type. If you are using this to update patterns and not synonyms (the default), then you need to specify new_type as "patterns" even though the parameter is listed as optional.