Field that allows making an external request to load the available values

Tabla de contenidos

Athento allows you to configure a field that makes an external request to obtain and display the available values that you can select.

To do so, you must first create a field of type “selection” or “multiple selection” and then select the subtype “External request”.

 

Once this option has been chosen, access the advanced administration of the field. At the bottom of this section you will find the “Choice API REST Metadata Type Configs” section, where you must configure the following attributes:

  • Request method path (Mandatory): Specifies the method path that will be responsible for making the request to obtain the options.

  • Username (Optional): Username that will be used to make the request.

  • Password (Optional): Password that will be used in the request.

The method configured in “Request method path” must be a Python function that meets the following requirements:

  1. Receive five arguments:

    • username: Configured username.

    • password: Configured password.

    • page: Current page of the selector.

    • pageSize: Number of elements per page in the selector.

    • request_search: Search term entered by the user in the selector.

  2. Make a call to an external URL using these arguments.

  3. Return a dictionary with the following structure:

    {
        'entries': [
            {'value': 'opcion1', 'label': 'Option 1'},
            {'value': 'opcion2', 'label': 'Option 2'}
        ],
        'hasMore': True  # Indicates whether there are more options available for pagination.
    }

Implementation example:

def request(**kwargs):
result = <call_to_external_url(arguments)>

options = <mapping_of_options_from_result>

return {
'entries': options,
'hasMore': <determine_whether_more_options_exist_or_not_from_result>
}

 

You can also include additional data in the options if you need more information in each one. For example:

{
    'entries': [
        {'value': '123', 'label': 'Client A', 'email': 'clientea@email.com'},
        {'value': '456', 'label': 'Client B', 'email': 'clienteb@email.com'}
    ],
    'hasMore': False
}

With this configuration, the field will be able to dynamically obtain the options from an external source, facilitating the management and updating of data in Athento.

Example:

You can also return additional data in the options. Below you have an example  returning additional data in the options.