User Scripts
Overview
User Scripts are Python-based automation tools that execute operations on a predetermined list of users. Users can be selected either through custom filters configured by the administrator or by importing rows from a CSV file. These scripts enable you to:
- Retrieve information about users in bulk
- Perform batch operations on selected users
- Automate repetitive user management tasks
Note: User Scripts must be executed manually by the administrator.
Accessing User Scripts
To access the User Scripts configuration screen:
User Object Reference
Overview
The script execution context provides access to a special User object, referenced as either user or obj. This object allows you to:
- Read and modify user attributes
- Perform operations on the managed user
- Execute special actions related to the user
Attributes
The user object exposes the following attributes:
| Name | Type | Description |
|---|---|---|
obj_id |
integer | user |
username |
string | username field of the current user (read/write) |
username_length |
integer | username_length field of the user (read/write) |
first_name |
string | first_name field of the current user (read/write) |
last_name |
string | last_name field of the current user (read/write) |
email |
string | email user (read/write) |
external_id |
string | external_id field of the current user (read/write) |
klass |
string | klass field of the current user (read/write) |
is_active |
boolean | user (read/write) |
date_joined |
datetime | user joined (read-only) |
first_login |
datetime | user first login (read-only) |
last_login |
datetime | user last login (read-only) |
expiration |
datetime | user expiration |
last_update |
datetime | user last |
organization_id |
integer | Numeric user organization |
avatar_url |
string | avatar_url field of the user (read/write) |
description |
string | description field of the current user (read/write) |
Methods
The user object provides the following methods for managing profiles and attributes:
profile_add()
Adds a specific profile to the user. You can add using the id or the short name of the profile.
Parameters:
-
id(integer) - Profile ID to add -
short_name(string) - Profile short name to add
Note: Use either id OR short_name, not both.
Returns:
-
updated(boolean) - Whether the operation succeeded -
message(string) - Status or error message
Examples:
# Add profile by ID
updated, message = user.profile_add(id=12)
# Add profile by short name
updated, message = user.profile_add(short_name="aaa-01")
profile_remove()
Removes a specific profile from the user. You can remove using the id or the short name of the profile.
Parameters:
-
id(integer) - Profile ID to remove -
short_name(string) - Profile short name to remove
Note: Use either id OR short_name, not both.
Returns:
-
updated(boolean) - Whether the operation succeeded -
message(string) - Status or error message
Examples:
# Remove profile by ID
updated, message = user.profile_remove(id=12)
# Remove profile by short name
updated, message = user.profile_remove(short_name="aaa-01")
attribute_add()
Adds a specific attribute to the user. You must provide the attribute name, value, and optionally an operation.
Parameters:
-
attr(string, required) - Attribute name to add -
value(string, required) - Value to assign to the attribute -
operation(string, optional) - Operator to use (default:=)- Available options:
=,+=,:=
- Available options:
Returns:
-
updated(boolean) - Whether the operation succeeded -
message(string) - Status or error message
Example:
updated, message = user.attribute_add(
attr='Username',
value="zequenze",
operation='+='
)
attribute_remove()
Removes a specific attribute from the user. You must provide the attribute name, value, and optionally an operation.
Parameters:
-
attr(string, required) - Attribute name to remove -
value(string, required) - Value to remove from the attribute -
operation(string, optional) - Operator to use (default:=)- Available options:
=,+=,:=
- Available options:
Returns:
-
updated(boolean) - Whether the operation succeeded -
message(string) - Status or error message
Example:
updated, message = user.attribute_remove(
attr='Username',
value="zequenze",
operation='+='
)
check_attribute_add()
Adds a specific check attribute to the user. You must provide the attribute name, value, and optionally an operation.
Parameters:
-
attr(string, required) - Check attribute name to add -
value(string, required) - Value to assign to the check attribute -
operation(string, optional) - Operator to use (default:=)- Available options:
=,+=,:=
- Available options:
Returns:
-
updated(boolean) - Whether the operation succeeded -
message(string) - Status or error message
Example:
updated, message = user.check_attribute_add(
attr='Max-Daily-Session',
value=4,
operation='=='
)
check_attribute_remove()
Removes a specific check attribute from the user. You must provide the attribute name, value, and optionally an operation.
Parameters:
-
attr(string, required) - Check attribute name to remove -
value(string, required) - Value to remove from the check attribute -
operation(string, optional) - Operator to use (default::=)- Available options:
:=,+=,==,!=,>,>=,<,<=,=*
- Available options:
Returns:
-
updated(boolean) - Whether the operation succeeded -
message(string) - Status or error message
Example:
updated, message = user.check_attribute_remove(
attr='Max-Daily-Session',
value=4,
operation='=='
)

