Search code examples
javascriptnode.jsdialogflow-es

Deleting Dialogflow entity type using Node.js


I'm trying to delete entity types through node.js. My approach is that, the entity name/s that would be deleted will come from a JSON file. I will then list the existing entities on my agent to find the entity id of the entity to be deleted. Then I will send the request to delete it but nothing's getting deleted.

Here's what I got so far:

//entitytodelete is the JSON file containing the entity name
entitytodelete.forEach(function(entityParams) {
 
entityClient 
.listEntityTypes({parent: projectAgentPath})

// look for entity ID of entity type to be deleted
.then((responses) => { const resources = responses[0];
    for (let i = 0; i < resources.length; i++) {
        const entityTypes = resources[i];
        if (entityTypes.displayName === entityParams) {
          return entityTypes;
        }
      }})
.then((entityParams) => {
console.log('The ID of the entity to delete is: ', JSON.stringify(entityParams.name));

const request = {
    parent: projectAgentPath,
    entityValues    : [entityParams.name],
};
return entityClient.batchDeleteEntityTypes(request);
})


Solution

  • As per conversation with @JoshMcD, changing the key entityValues to entityTypeNames worked since method batchDeleteEntityTypes() is intended to delete an entity type.

    See sample code:

    const request = {
        parent: projectAgentPath,
        entityTypeNames    : [entityParams.name], 
    };
    return entityClient.batchDeleteEntityTypes(request);