The Kubiya Users service provides a comprehensive interface for managing users and groups within your organization through the Kubiya platform.
It enables you to list users and groups with pagination support and comprehensive error handling.
from kubiya_workflow_sdk import KubiyaClientfrom kubiya_workflow_sdk.kubiya_services.exceptions import UserError, GroupError# Initialize clientclient = KubiyaClient( api_key="your-api-key", base_url="https://api.kubiya.ai")try: # List all users with default pagination users = client.users.list_users() print(f"Found {len(users)} users") for user in users: print(f"User: {user.get('name', 'N/A')} ({user.get('email', 'N/A')})") # List all groups groups = client.users.list_groups() print(f"Found {len(groups)} groups") for group in groups: print(f"Group: {group.get('name', 'N/A')}")except UserError as e: print(f"User operation failed: {e}")except GroupError as e: print(f"Group operation failed: {e}")
# Get users and filter by attributesusers = client.users.list_users(limit=1000)# Filter by email domaincompany_users = [user for user in users if user.get('email', '').endswith('@company.com')]print(f"Company users: {len(company_users)}")
try: groups = client.users.list_groups()except GroupError as e: print(f"Group operation failed: {e}") # Handle group-specific errors if "permission" in str(e).lower(): print("Insufficient permissions to list groups") elif "not found" in str(e).lower(): print("Groups endpoint not available")
def find_users_by_criteria( email_domain: Optional[str] = None, name_pattern: Optional[str] = None, status: Optional[str] = None) -> list: """Find users matching specific criteria""" try: all_users = client.users.list_users(limit=1000) filtered_users = all_users # Filter by email domain if email_domain: filtered_users = [ user for user in filtered_users if user.get('email', '').endswith(f'@{email_domain}') ] # Filter by name pattern if name_pattern: pattern = name_pattern.lower() filtered_users = [ user for user in filtered_users if pattern in user.get('name', '').lower() or pattern in user.get('email', '').lower() ] return filtered_users except UserError as e: logger.error(f"Failed to search users: {e}") return []# Usage examplescompany_users = find_users_by_criteria(email_domain="company.com")johns = find_users_by_criteria(name_pattern="john")
The Users service integrates seamlessly with other Kubiya services and workflows.
Use it for access control, audit logging, and organizational reporting.