Skip to content

DomoUser

DomoUser

DomoUser module for managing Domo users.

CreateUser_MissingRoleError

CreateUser_MissingRoleError(domo_instance, email_address)

Bases: ClassError

Exception raised when role_id is missing during user creation.

Source code in src/crew_dcs/classes/DomoUser.py
58
59
60
61
62
def __init__(self, domo_instance, email_address):
    super().__init__(
        domo_instance=domo_instance,
        message=f"Error creating user {email_address}: missing role_id parameter",
    )

DeleteUserError

DeleteUserError(
    res: ResponseGetData,
    message: str | None = None,
    user_id: str | None = None,
    **kwargs,
)

Bases: RouteError

Raised when user deletion operations fail.

Source code in src/crew_dcs/routes/user/exceptions.py
 94
 95
 96
 97
 98
 99
100
101
def __init__(
    self,
    res: rgd.ResponseGetData,
    message: str | None = None,
    user_id: str | None = None,
    **kwargs,
):
    super().__init__(res=res, entity_id=user_id, message=message, **kwargs)

DomoUser dataclass

DomoUser(
    auth: DomoAuth,
    id: str,
    raw: dict,
    display_name: str | None = None,
    email_address: str | None = None,
    role_id: int | None = None,
    department: str | None = None,
    title: str | None = None,
    avatar_key: str | None = None,
    avatar: Image | None = None,
    password: str | None = None,
    phone_number: str | None = None,
    web_landing_page: str | None = None,
    web_mobile_landing_page: str | None = None,
    employee_id: str | None = None,
    employee_number: str | None = None,
    hire_date: str | None = None,
    reports_to: str | None = None,
    publisher_domain: str | None = None,
    subscriber_domain: str | None = None,
    virtual_user_id: str | None = None,
    created_dt: datetime | None = None,
    last_activity_dt: datetime | None = None,
    custom_attributes: dict = dict(),
    domo_api_clients: list[Any] | None = None,
    domo_access_tokens: list[Any] | None = None,
    Role: Any | None = None,
    ApiClients: Any | None = None,
)

Bases: DomoEntity

A class for interacting with a Domo User

display_url property

display_url: str

Generate the URL to display this user in the Domo admin interface.

create async classmethod

create(
    auth: DomoAuth,
    display_name,
    email_address,
    role: Any,
    password: str | None = None,
    send_password_reset_email: bool = False,
    send_notification: bool = True,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Create a Domo user and return it, re-read with DomoUser.get_by_id.

Parameters:

Name Type Description Default
auth DomoAuth

Authentication object.

required
display_name str

Display name for the new user.

required
email_address str

Email address; validated before the request.

required
role Any

DomoRole to assign. Falsy uses the instance default role (DomoRoles.get_default_role).

required
password str | None

If given, set as the user's password after creation.

None
send_password_reset_email bool

If True and no password is given, send a password-reset email after creation.

False
send_notification bool

Whether to send the invite email. Set False to suppress it (v3 API sendNotification query param). See routes/user/core.py::create_user for the v1 sendInvite gotcha and its source.

True

Raises:

Type Description
InvalidEmailError

email_address is not a valid address.

User_CRUD_Error

The create request failed.

User_GET_Error

The read-back of the new user failed.

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
@classmethod
async def create(
    cls,
    auth: DomoAuth,
    display_name,
    email_address,
    role: Any,  # DomoRole - will use default role if none provided
    password: str | None = None,
    send_password_reset_email: bool = False,
    send_notification: bool = True,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    """Create a Domo user and return it, re-read with `DomoUser.get_by_id`.

    Args:
        auth: Authentication object.
        display_name (str): Display name for the new user.
        email_address (str): Email address; validated before the request.
        role: DomoRole to assign. Falsy uses the instance default role
            (`DomoRoles.get_default_role`).
        password: If given, set as the user's password after creation.
        send_password_reset_email: If True and no password is given, send
            a password-reset email after creation.
        send_notification: Whether to send the invite email. Set False to
            suppress it (v3 API `sendNotification` query param). See
            routes/user/core.py::create_user for the v1 `sendInvite`
            gotcha and its source.

    Raises:
        InvalidEmailError: email_address is not a valid address.
        User_CRUD_Error: The create request failed.
        User_GET_Error: The read-back of the new user failed.
    """

    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    if not role:
        from .DomoInstanceConfig.role import DomoRoles

        role = await DomoRoles(auth=auth).get_default_role(context=context)

    res = await user_routes.create_user(
        auth=auth,
        display_name=display_name,
        email_address=email_address,
        role_id=role.id,
        send_notification=send_notification,
        context=context,
    )

    domo_user = await DomoUser.get_by_id(
        auth=auth,
        user_id=res.response.get("id") or res.response.get("userId"),
        context=context,
    )

    if password and domo_user:
        await domo_user.reset_password(new_password=password, context=context)

    elif send_password_reset_email and domo_user:
        await domo_user.request_password_reset(
            domo_instance=auth.domo_instance,
            email=domo_user.email_address,
            context=context,
        )

    return domo_user

delete async

delete(
    debug_api: bool = False,
    session: AsyncClient | None = None,
    debug_num_stacks_to_drop=2,
    parent_class=None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
async def delete(
    self,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    debug_num_stacks_to_drop=2,
    parent_class=None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        parent_class=parent_class,
        **context_kwargs,
    )

    res = await user_routes.delete_user(
        auth=self.auth,
        user_id=self.id,
        context=context,
    )

    return res  # noqa: RET504

download_avatar async

download_avatar(
    pixels: int = 300,
    folder_path="./images",
    img_name=None,
    auth: DomoAuth | None = None,
    is_download_image: bool = True,
    debug_api: bool = False,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

downloads a user's avatar to a folder and returns the byte representation of the image

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
async def download_avatar(
    self,
    pixels: int = 300,
    folder_path="./images",
    img_name=None,  # will default to user_id
    auth: DomoAuth | None = None,
    is_download_image: bool = True,  # option to prevent downloading the image file
    debug_api: bool = False,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    """downloads a user's avatar to a folder
    and returns the byte representation of the image
    """
    auth = auth or self.auth

    context = RouteContext.build_context(
        context=context, debug_api=debug_api, **context_kwargs
    )

    res = await user_routes.download_avatar(
        auth=self.auth,
        user_id=self.id,
        pixels=pixels,
        folder_path=folder_path,
        img_name=img_name,
        is_download_image=is_download_image,
        context=context,
    )

    if return_raw:
        return res

    self.avatar = ImageUtils.from_bytestr(data=res.response)

    return self.avatar

from_virtual_dict classmethod

from_virtual_dict(auth, obj: dict[str, Any])

Create DomoUser instance from virtual user JSON response.

Virtual users are created when content is published across instances.

Source code in src/crew_dcs/classes/DomoUser.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
@classmethod
def from_virtual_dict(cls, auth, obj: dict[str, Any]):
    """Create DomoUser instance from virtual user JSON response.

    Virtual users are created when content is published across instances.
    """
    return cls(
        id=obj["id"],
        auth=auth,
        publisher_domain=obj.get("publisherDomain"),
        subscriber_domain=obj.get("subscriberDomain"),
        virtual_user_id=obj.get("virtualUserId"),
        raw=obj,
    )

get_api_clients async

get_api_clients(
    debug_api: bool = False,
    session: AsyncClient | None = None,
    debug_num_stacks_to_drop: int = 2,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

retrieves Client_IDs for this user (assuming the authenticated user has manage rights). Note : the values will be masked, raw text values can only be retrieved via the UI

Source code in src/crew_dcs/classes/DomoUser.py
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
async def get_api_clients(
    self,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    debug_num_stacks_to_drop: int = 2,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    """
    retrieves Client_IDs for this user (assuming the authenticated user has manage rights).
    Note : the values will be masked, raw text values can only be retrieved via the UI
    """

    from .DomoInstanceConfig.api_client import ApiClients

    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop + 1,
        **context_kwargs,
    )

    api_clients = ApiClients(auth=self.auth)

    res = await api_clients.get(
        context=context,
    )

    if return_raw:
        return res

    domo_clients = (
        [
            domo_client
            for domo_client in res.response
            if domo_client.domo_user.id == self.id  # type: ignore
        ]
        if isinstance(res, ResponseGetData)
        else []
    )

    if not domo_clients:
        await logger.info(
            f"Domo User {self.id} - {self.display_name} does not have any Client_IDs"
        )
        return False

    self.domo_api_clients = domo_clients

    return self.domo_api_clients

get_by_id async classmethod

get_by_id(
    auth: DomoAuth,
    user_id: str,
    return_raw: bool = False,
    debug_api: bool = False,
    debug_num_stacks_to_drop=2,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Retrieve a Domo user by ID.

Parameters:

Name Type Description Default
auth DomoAuth

Authentication object

required
user_id str

User ID to retrieve

required
return_raw bool

If True, return raw API response instead of DomoUser instance

False
debug_api bool

Enable debug output for API call

False
debug_num_stacks_to_drop

Number of stack frames to drop in logging

2
session AsyncClient | None

Optional httpx session for connection pooling

None
context RouteContext | None

Optional RouteContext for API call configuration

None
**context_kwargs

Additional context parameters

{}

Returns:

Type Description

DomoUser instance or ResponseGetData if return_raw=True

Raises:

Type Description
User_GET_Error

If user retrieval fails

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
@classmethod
async def get_by_id(
    cls,
    auth: DomoAuth,
    user_id: str,
    return_raw: bool = False,
    debug_api: bool = False,
    debug_num_stacks_to_drop=2,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    """Retrieve a Domo user by ID.

    Args:
        auth: Authentication object
        user_id: User ID to retrieve
        return_raw: If True, return raw API response instead of DomoUser instance
        debug_api: Enable debug output for API call
        debug_num_stacks_to_drop: Number of stack frames to drop in logging
        session: Optional httpx session for connection pooling
        context: Optional RouteContext for API call configuration
        **context_kwargs: Additional context parameters

    Returns:
        DomoUser instance or ResponseGetData if return_raw=True

    Raises:
        User_GET_Error: If user retrieval fails
    """

    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    res = await user_routes.get_by_id(
        auth=auth,
        user_id=user_id,
        context=context,
    )

    if return_raw:
        return res

    if not res.is_success:
        return None

    domo_user = cls.from_dict(obj=res.response, auth=auth)

    try:
        await domo_user.get_role(
            context=context,
        )
    except DomoError as e:
        await logger.exception(f"unable to get role for user {domo_user.id}: {e}")

    return domo_user

request_password_reset async classmethod

request_password_reset(
    domo_instance: str,
    email: str,
    locale: str = "en-us",
    debug_api: bool = False,
    session: AsyncClient | None = None,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
)

request password reset email. Note: does not require authentication.

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
@classmethod
async def request_password_reset(
    cls,
    domo_instance: str,
    email: str,
    locale: str = "en-us",
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
):
    """request password reset email.  Note: does not require authentication."""
    return await user_routes.request_password_reset(
        domo_instance=domo_instance,
        email=email,
        locale=locale,
        context=context,
        debug_api=debug_api,
        session=session,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        parent_class=cls.__name__,
    )

reset_password async

reset_password(
    new_password: str,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

reset your password, will respect password restrictions set up in the Domo UI

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
async def reset_password(
    self: "DomoUser",
    new_password: str,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    """reset your password, will respect password restrictions set up in the Domo UI"""
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    res = await user_routes.reset_password(
        auth=self.auth,
        user_id=self.id,
        new_password=new_password,
        context=context,
    )

    self.password = new_password

    return res

set_user_landing_page async

set_user_landing_page(
    page_id: str,
    id: str,
    auth: DomoAuth | None = None,
    debug_api: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
async def set_user_landing_page(
    self,
    page_id: str,
    id: str,
    auth: DomoAuth | None = None,
    debug_api: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context, debug_api=debug_api, **context_kwargs
    )

    res = await user_routes.set_user_landing_page(
        auth=auth or self.auth,
        page_id=page_id,
        user_id=self.id or id,
        context=context,
    )

    return res  # noqa: RET504

toggle_direct_signon_access async

toggle_direct_signon_access(
    is_enable_direct_signon: bool | None = None,
    note: str | None = None,
    session: AsyncClient | None = None,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
async def toggle_direct_signon_access(
    self: "DomoUser",
    is_enable_direct_signon: bool | None = None,
    note: str | None = None,  # add a note to the sso entry
    session: httpx.AsyncClient | None = None,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    response = ""
    if is_enable_direct_signon is not None:
        res = await sso_routes.toggle_user_direct_signon_access(
            auth=self.auth,
            user_id_ls=[self.id],
            is_enable_direct_signon=is_enable_direct_signon,
            context=context,
            return_raw=return_raw,
        )

        response = res.response

    if note is not None:
        note_res = await sso_routes.add_note_to_user_direct_signon(
            auth=self.auth,
            user_id_ls=[self.id],
            note=note,
            context=context,
            return_raw=return_raw,
        )

        response += note_res.response

    if return_raw:
        return res

    res.response = response
    return res

update_properties async

update_properties(
    property_ls: list[UserProperty],
    return_raw: bool = False,
    auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
async def update_properties(  # noqa: RET503
    self,
    property_ls: list[
        UserProperty
    ],  # use the UserProperty class to define a list of user properties to update, see user route documentation to see a list of UserProperty_Types that can be updated
    return_raw: bool = False,
    auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    auth = auth or self.auth

    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        **context_kwargs,
    )

    res = await user_routes.update_user(
        auth=auth,
        user_id=self.id,
        user_property_ls=property_ls,
        context=context,
    )
    if return_raw:
        return res

    # Update self using from_dict pattern
    if res.response:
        updated_user = self.from_dict(auth=auth, obj=res.response)
        # Copy updated attributes back to self
        for key, value in updated_user.__dict__.items():
            if key not in ["auth"]:  # Don't overwrite auth
                setattr(self, key, value)

        return updated_user

upload_avatar async

upload_avatar(
    avatar: Image,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
async def upload_avatar(
    self,
    avatar: Image.Image,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        **context_kwargs,
    )

    avatar = ImageUtils.crop_square(avatar)

    res = await user_routes.upload_avatar(
        auth=self.auth,
        user_id=self.id,
        img_bytestr=ImageUtils.to_bytes(avatar),
        img_type=avatar.format,
        context=context,
    )

    if return_raw:
        return res

    await asyncio.sleep(2)

    return await self.download_avatar(context=context)

upsert_avatar async

upsert_avatar(
    avatar: Image,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
async def upsert_avatar(
    self,
    avatar: Image.Image,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        **context_kwargs,
    )

    avatar = ImageUtils.crop_square(avatar)

    res = "images are the same"
    if not are_same_image(domo_default_img, avatar):
        await logger.info(f"Updating avatar for user {self.id} ({self.name})")
        res = await user_routes.upload_avatar(
            auth=self.auth,
            user_id=self.id,
            img_bytestr=ImageUtils.to_bytes(avatar),
            img_type=avatar.format,
            context=context,
        )

        if return_raw:
            return res
    else:
        await logger.info(
            f"Keeping existing avatar for user {self.id} ({self.name}) - image unchanged"
        )

    await asyncio.sleep(2)

    return await self.download_avatar(context=context)

DomoUser_NoSearchError

DomoUser_NoSearchError(
    cls_instance,
    message: str = "No users found matching search criteria",
    domo_instance: str | None = None,
)

Bases: ClassError

Exception raised when user search operations fail.

Source code in src/crew_dcs/classes/DomoUser.py
68
69
70
71
72
73
74
75
76
77
78
def __init__(
    self,
    cls_instance,
    message: str = "No users found matching search criteria",
    domo_instance: str | None = None,
):
    super().__init__(
        cls_instance=cls_instance,
        domo_instance=domo_instance,
        message=message,
    )

DomoUsers dataclass

DomoUsers(
    auth: DomoAuth,
    users: list[DomoUser] = list(),
    virtual_users: list[DomoUser] = list(),
)

Bases: DomoManager

a class for searching for Users

get async

get(
    *args,
    return_raw: bool = False,
    debug_api: bool = False,
    debug_num_stacks_to_drop=2,
    session: AsyncClient | None = None,
    context: RouteContext | None = None,
    **kwargs,
) -> list[DomoUser]

retrieves all users from Domo

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
async def get(
    self,
    *args,
    return_raw: bool = False,
    debug_api: bool = False,
    debug_num_stacks_to_drop=2,
    session: httpx.AsyncClient | None = None,
    context: RouteContext | None = None,
    **kwargs,
) -> list[DomoUser]:
    """retrieves all users from Domo"""
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **kwargs,
    )

    res = await user_routes.get_all_users(
        auth=self.auth,
        context=context,
    )

    if return_raw:
        return res

    self.users = self._users_to_domo_user(user_ls=res.response, auth=self.auth)
    return self.users

get_virtual_user_by_subscriber_instance async

get_virtual_user_by_subscriber_instance(
    subscriber_instance_ls: str,
    debug_api: bool = False,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
async def get_virtual_user_by_subscriber_instance(
    self,
    subscriber_instance_ls: str,
    debug_api: bool = False,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context, debug_api=debug_api, **context_kwargs
    )

    res = await user_routes.search_virtual_user_by_subscriber_instance(
        auth=self.auth,
        subscriber_instance_ls=subscriber_instance_ls,
        context=context,
    )

    if return_raw:
        return res

    domo_users = self._users_to_virtual_user(res.response, auth=self.auth)
    self.virtual_users = domo_users
    return domo_users

search_by_email async

search_by_email(
    email: str | list[str],
    only_allow_one: bool = True,
    debug_api: bool = False,
    debug_num_stacks_to_drop=2,
    return_raw: bool = False,
    suppress_no_results_error: bool = False,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> list[DomoUser] | DomoUser | ResponseGetData | bool

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
async def search_by_email(
    self,
    email: str | list[str],
    only_allow_one: bool = True,
    debug_api: bool = False,
    debug_num_stacks_to_drop=2,
    return_raw: bool = False,
    suppress_no_results_error: bool = False,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> list[DomoUser] | DomoUser | ResponseGetData | bool:
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    emails = [email] if isinstance(email, str) else email

    try:
        res = await user_routes.search_users_by_email(
            user_email_ls=emails,
            auth=self.auth,
            return_raw=return_raw,
            context=context,
        )

    except SearchUserNotFoundError:
        if suppress_no_results_error:
            return []

        raise

    if return_raw:
        return res

    domo_users = self._users_to_domo_user(res.response, auth=self.auth)

    if not only_allow_one:
        return domo_users

    domo_users = self._util_match_domo_users_to_emails(domo_users, emails)

    if not domo_users:
        raise DomoUser_NoSearchError(
            cls_instance=self,
            message=f"unable to find {','.join(emails)}",
            domo_instance=self.auth.domo_instance,
        )

    return domo_users[0]

search_by_id async

search_by_id(
    user_ids: list[str],
    suppress_no_results_error: bool = False,
    only_allow_one: bool = True,
    debug_num_stacks_to_drop=2,
    debug_api: bool = False,
    return_raw: bool = False,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> list[DomoUser] | DomoUser | ResponseGetData | bool

Calls route

Source code in src/crew_dcs/classes/DomoUser.py
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
async def search_by_id(
    self,
    user_ids: list[str],  # can search for one or multiple users
    suppress_no_results_error: bool = False,
    only_allow_one: bool = True,
    debug_num_stacks_to_drop=2,
    debug_api: bool = False,
    return_raw: bool = False,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> list[DomoUser] | DomoUser | ResponseGetData | bool:
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    res = None

    try:
        res = await user_routes.search_users_by_id(
            return_raw=return_raw,
            user_ids=user_ids,
            auth=self.auth,
            context=context,
        )

    except SearchUserNotFoundError as e:
        if suppress_no_results_error:
            await logger.exception(f"user search found no results: {e}")

            if only_allow_one:
                return False
            return []

        raise

    if return_raw:
        return res

    domo_users = self._users_to_domo_user(user_ls=res.response, auth=self.auth)

    if only_allow_one:
        return domo_users[0]

    return domo_users

upsert async

upsert(
    email_address: str,
    display_name: str | None = None,
    role: Any | None = None,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
) -> DomoUser

Upsert a Domo user - update if exists, create if not.

Parameters:

Name Type Description Default
email_address str

User email address (required)

required
display_name str | None

User display name (optional)

None
role Any | None

DomoRole object (optional, will use default if not provided on creation)

None
debug_api bool

Enable debug output for API calls

False
debug_num_stacks_to_drop int

Number of stack frames to drop in logging

2
session AsyncClient | None

Optional httpx session for connection pooling

None

Returns:

Name Type Description
DomoUser DomoUser

The created or updated user

Raises:

Type Description
ValidationError

If email address is invalid

Source code in src/crew_dcs/classes/DomoUser.py
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
@log_call(action_name="class")
async def upsert(
    self,
    email_address: str,
    display_name: str | None = None,
    role: Any | None = None,  # DomoRole
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
) -> DomoUser:
    """Upsert a Domo user - update if exists, create if not.

    Args:
        email_address: User email address (required)
        display_name: User display name (optional)
        role: DomoRole object (optional, will use default if not provided on creation)
        debug_api: Enable debug output for API calls
        debug_num_stacks_to_drop: Number of stack frames to drop in logging
        session: Optional httpx session for connection pooling

    Returns:
        DomoUser: The created or updated user

    Raises:
        ValidationError: If email address is invalid
    """
    is_valid_email(email_address)

    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
    )

    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
    )

    try:
        # Type narrowing: when only_allow_one=True and successful, returns DomoUser
        domo_user: DomoUser = await self.search_by_email(
            email=email_address,
            only_allow_one=True,
            context=context,
        )

        await logger.info(f"domo_user found {domo_user.id}")

        # Type guard to ensure we have a DomoUser instance
        if not isinstance(domo_user, DomoUser):
            raise ValueError(f"Expected DomoUser, got {type(domo_user)}")

        property_ls = []
        if display_name:
            property_ls.append(
                user_routes.UserProperty(
                    user_routes.UserProperty_Type.display_name, display_name
                )
            )

        if role and hasattr(role, "id") and role.id:
            property_ls.append(
                user_routes.UserProperty(
                    user_routes.UserProperty_Type.role_id, role.id
                )
            )

        if property_ls:
            await logger.info("Updating user properties for existing user.")
            await domo_user.update_properties(
                property_ls=property_ls,
                context=context,
            )
        return domo_user

    except (SearchUserNotFoundError, DomoUser_NoSearchError):
        # User doesn't exist, create new one

        await logger.info("User not found, creating new user.")

        created_user = await DomoUser.create(
            display_name=display_name
            or f"{email_address} - via dl {dt.date.today()}",
            email_address=email_address,
            auth=self.auth,
            role=role,
            context=context,
        )

        # Type guard for created user
        if created_user is None:
            raise ValueError(f"Failed to create user for email: {email_address}")  # noqa: B904

        await self.get(context=context)

        return created_user

DownloadAvatar_Error

DownloadAvatar_Error(
    user_id: str | None = None,
    res: ResponseGetData | None = None,
    message: str | None = None,
    **kwargs,
)

Bases: RouteError

Raised when user avatar download operations fail.

Source code in src/crew_dcs/routes/user/exceptions.py
154
155
156
157
158
159
160
161
162
163
def __init__(
    self,
    user_id: str | None = None,
    res: rgd.ResponseGetData | None = None,
    message: str | None = None,
    **kwargs,
):
    if not message:
        message = "Avatar download failed"
    super().__init__(res=res, entity_id=user_id, message=message, **kwargs)

ResetPasswordPasswordUsedError

ResetPasswordPasswordUsedError(
    user_id: str | None = None,
    res: ResponseGetData | None = None,
    message: str | None = None,
    **kwargs,
)

Bases: RouteError

Raised when attempting to reset password to a previously used password.

Source code in src/crew_dcs/routes/user/exceptions.py
139
140
141
142
143
144
145
146
147
148
def __init__(
    self,
    user_id: str | None = None,
    res: rgd.ResponseGetData | None = None,
    message: str | None = None,
    **kwargs,
):
    if not message:
        message = "Password was previously used"
    super().__init__(res=res, entity_id=user_id, message=message, **kwargs)

SearchUserNotFoundError

SearchUserNotFoundError(
    search_criteria: str,
    res=None,
    message: str | None = None,
    **kwargs,
)

Bases: RouteError

Raised when user search operations return no results.

Source code in src/crew_dcs/routes/user/exceptions.py
67
68
69
70
71
72
def __init__(
    self, search_criteria: str, res=None, message: str | None = None, **kwargs
):
    if not message:
        message = f"No users found matching: {search_criteria}"
    super().__init__(res=res, entity_id=search_criteria, message=message, **kwargs)

UserAttributes_CRUD_Error

UserAttributes_CRUD_Error(
    operation: str,
    attribute_id: str | None = None,
    message: str | None = None,
    res=None,
    **kwargs,
)

Bases: RouteError

Raised when user attributes create, update, or delete operations fail.

Source code in src/crew_dcs/routes/user/exceptions.py
122
123
124
125
126
127
128
129
130
131
132
133
def __init__(
    self,
    operation: str,
    attribute_id: str | None = None,
    message: str | None = None,
    res=None,
    **kwargs,
):
    if not message:
        message = f"User attributes {operation} operation failed"

    super().__init__(res=res, entity_id=attribute_id, message=message, **kwargs)

UserAttributes_GET_Error

UserAttributes_GET_Error(
    attribute_id: str | None = None,
    message: str | None = None,
    res=None,
    **kwargs,
)

Bases: RouteError

Raised when user attributes retrieval operations fail.

Source code in src/crew_dcs/routes/user/exceptions.py
107
108
109
110
111
112
113
114
115
116
def __init__(
    self,
    attribute_id: str | None = None,
    message: str | None = None,
    res=None,
    **kwargs,
):
    if not message:
        message = "User attributes retrieval failed"
    super().__init__(res=res, entity_id=attribute_id, message=message, **kwargs)

UserSharing_Error

UserSharing_Error(
    operation: str,
    user_id: str | None = None,
    res=None,
    message: str | None = None,
    **kwargs,
)

Bases: RouteError

Raised when user sharing operations fail.

Source code in src/crew_dcs/routes/user/exceptions.py
78
79
80
81
82
83
84
85
86
87
88
def __init__(
    self,
    operation: str,
    user_id: str | None = None,
    res=None,
    message: str | None = None,
    **kwargs,
):
    if not message:
        message = f"User sharing {operation} failed"
    super().__init__(res=res, entity_id=user_id, message=message, **kwargs)

User_CRUD_Error

User_CRUD_Error(
    operation: str,
    user_id: str | None = None,
    res=None,
    message: str | None = None,
    **kwargs,
)

Bases: RouteError

Raised when user create, update, or delete operations fail.

Source code in src/crew_dcs/routes/user/exceptions.py
49
50
51
52
53
54
55
56
57
58
59
60
61
def __init__(
    self,
    operation: str,
    user_id: str | None = None,
    res=None,
    message: str | None = None,
    **kwargs,
):
    # Use provided message if available, otherwise create default
    if not message:
        message = f"User {operation} operation failed"

    super().__init__(res=res, entity_id=user_id, message=message, **kwargs)

User_GET_Error

User_GET_Error(
    user_id: str | None = None,
    res=None,
    message: str | None = None,
    **kwargs,
)

Bases: RouteError

Raised when user retrieval operations fail.

Source code in src/crew_dcs/routes/user/exceptions.py
37
38
39
40
41
42
43
def __init__(
    self, user_id: str | None = None, res=None, message: str | None = None, **kwargs
):
    if not message:
        message = "User retrieval failed"

    super().__init__(res=res, entity_id=user_id, message=message, **kwargs)