Skip to content

Fail to create entity with pattern values #359

@victorzhao1990

Description

@victorzhao1990

In the Conversation API, it should be possible to create new entity with pattern values in either workspace creation phase (creat_workspace) or by invoking create_entity. They failed and return Error: Invalid Request Body, Code: 400. A feasible way is by creating the entity with only the name but no values and add entity value separately.

Request payload:

CreateEntity entities = [{
    'entity': 'pattern_entity',
    'values': [{
        'value': 'value0', 'patterns': ['\\d{6}\\w{1}\\d{7}'], 'value_type': [patterns']
     }, 
     {'value': 'value1', 
      'patterns': ['[-9][0-9][0-9][0-9][0-9]~! [1-9][1-9][1-9][1-9][1-9][1-9]'], 
      'value_type': ['patterns']}, 
     {'value': 'value2', 
      'patterns': ['[a-z-9]{17}'], 
      'value_type': ['patterns']}, 
     {'value': 'value3', 
      'patterns': [
           '\\d{3}(\\ |-)\\d{3}(\\ |-)\\d{4}', 
           '\\(\\d{3}\\)(\\ |-)\\d{3}(\\ |-)\\d{4}'], 
      'value_type': 'patterns'}, 
     {'value': 'value4', 
      'patterns': ['\\b\\d{5}\\b'], 
      'value_type': ['patterns']}]
}]

This code works:

conv.create_entity(workspace_id=resp['workspace_id'], entity=entities['entity'])
for idx in range(len(entities['values'])):
        conv.create_value(
              workspace_id=resp['workspace_id'], entity=entities['entity'],
              value=entities['values'][idx]['value'], 
              patterns=entities['values'][idx]['patterns'], value_type='patterns')

These don't work:

conv.create_entity(
       workspace_id=resp['workspace_id'], 
       entity=entities['entity'], values=entities['values']
)
conversation.create_workspace(
    name='API test',
    description='Example workspace created via API',
    entities=entities
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions