UserAttr.names - Python API

Returns names of all attributes defined for a given user. The list is not guaranteed to be sorted in any way.

names

user.attr.names(self)

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class UserAttrNames(Service):
    def handle(self):

        # Current user's data
        username = 'admin1'
        password = 'abxqDJpXMVXYEO8NOGx9nVZvv4xSew9'
        current_app = 'CRM'
        remote_addr = '127.0.0.1'
        user_agent = 'Firefox 139.0'

        # Log in current user
        session = self.sso.user.login(
            self.cid, username, password, current_app, remote_addr, user_agent)

        # Get UST
        ust = session.ust

        # Get user object
        user = self.sso.user.get_user_by_id(
            self.cid, session.user_id, ust, current_app, remote_addr)

        # Prepare a list of dictionaries with attributes to create
        data = [
            {'name':'my-attr1-zxc-11', 'value':'11'},
            {'name':'my-attr2-zxc-22', 'value':'22'},
            {'name':'my-attr3-zxc-33', 'value':'33'},
        ]

        # Create new attributes
        user.attr.create_many(data)

        # Get names of all attributes for that user
        result = user.attr.names()

        self.logger.info('Result -> %s', result)
INFO - Result -> ['my-attr1-zxc-11', 'my-attr2-zxc-22', 'my-attr3-zxc-33']