Skip to content

access

access

Access

Bases: DomoEnumMixin

abc for the concept of managing access levels to Domo entities.

AccountAccess

Bases: Access, Enum

v2 API sharing permissions (users and groups).

AccountAccess_v1

Bases: Access, Enum

Legacy v1 API sharing permissions (users only).

generate_share_account_payload

generate_share_account_payload(
    access_level: AccountAccess | AccountAccess_v1 | str,
    user_id: int | None = None,
    group_id: int | None = None,
    use_v1_api: bool = False,
) -> dict

Orchestrator function to generate appropriate sharing payload.

This function determines which payload generation function to use based on: - The access_level type (v1 or v2 enum) - The use_v1_api flag - Whether a group_id is provided (forces v2)

Parameters:

Name Type Description Default
access_level AccountAccess | AccountAccess_v1 | str

Access level enum or string

required
user_id int | None

ID of the user to share with

None
group_id int | None

ID of the group to share with (forces v2 API)

None
use_v1_api bool

Force use of v1 API (ignored if group_id provided)

False

Returns:

Type Description
dict

Dictionary payload for appropriate share API

Raises:

Type Description
ValueError

If group_id provided with v1 access level or use_v1_api=True

Example

V2 with user

payload = generate_share_account_payload( ... access_level=AccountAccess.CAN_VIEW, ... user_id=12345 ... )

V2 with group (auto-detects v2 needed)

payload = generate_share_account_payload( ... access_level=AccountAccess.CAN_VIEW, ... group_id=67890 ... )

V1 explicitly

payload = generate_share_account_payload( ... access_level=AccountAccess_v1.CAN_VIEW, ... user_id=12345 ... )

Source code in src/crew_dcs/routes/account/access.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
def generate_share_account_payload(
    access_level: AccountAccess | AccountAccess_v1 | str,
    user_id: int | None = None,
    group_id: int | None = None,
    use_v1_api: bool = False,
) -> dict:
    """Orchestrator function to generate appropriate sharing payload.

    This function determines which payload generation function to use based on:
    - The access_level type (v1 or v2 enum)
    - The use_v1_api flag
    - Whether a group_id is provided (forces v2)

    Args:
        access_level: Access level enum or string
        user_id: ID of the user to share with
        group_id: ID of the group to share with (forces v2 API)
        use_v1_api: Force use of v1 API (ignored if group_id provided)

    Returns:
        Dictionary payload for appropriate share API

    Raises:
        ValueError: If group_id provided with v1 access level or use_v1_api=True

    Example:
        >>> # V2 with user
        >>> payload = generate_share_account_payload(
        ...     access_level=AccountAccess.CAN_VIEW,
        ...     user_id=12345
        ... )

        >>> # V2 with group (auto-detects v2 needed)
        >>> payload = generate_share_account_payload(
        ...     access_level=AccountAccess.CAN_VIEW,
        ...     group_id=67890
        ... )

        >>> # V1 explicitly
        >>> payload = generate_share_account_payload(
        ...     access_level=AccountAccess_v1.CAN_VIEW,
        ...     user_id=12345
        ... )
    """
    # Determine if we need v1 or v2
    is_v1_enum = isinstance(access_level, AccountAccess_v1)

    # Force v2 if group_id provided
    if group_id:
        if is_v1_enum:
            raise ValueError("Cannot share with groups using v1 access levels")
        if use_v1_api:
            raise ValueError("Cannot share with groups using v1 API")

        return generate_share_account_v2_payload(
            access_level=access_level, group_id=group_id
        )

    # Use v1 if explicitly requested or v1 enum provided
    if is_v1_enum or use_v1_api:
        if not user_id:
            raise ValueError("user_id required for v1 API")

        # Convert v2 enum to v1 if needed
        if not is_v1_enum:
            # Map v2 access levels to v1
            v2_to_v1_mapping = {
                "CAN_VIEW": AccountAccess_v1.CAN_VIEW,
                "CAN_EDIT": AccountAccess_v1.CAN_EDIT,
                "CAN_SHARE": AccountAccess_v1.OWNER,
                "OWNER": AccountAccess_v1.OWNER,
            }

            if isinstance(access_level, str):
                access_level = AccountAccess.get(access_level)

            access_level = v2_to_v1_mapping.get(
                access_level.value, AccountAccess_v1.CAN_VIEW
            )

        return generate_share_account_v1_payload(
            user_id=user_id, access_level=access_level
        )

    # Default to v2
    return generate_share_account_v2_payload(access_level=access_level, user_id=user_id)

generate_share_account_v1_payload

generate_share_account_v1_payload(
    user_id: int, access_level: AccountAccess_v1
) -> dict

Generate v1 API sharing payload for users only.

V1 API limitations: - Only supports sharing with users (no groups) - Limited permission set: READ, WRITE, OWNER

Parameters:

Name Type Description Default
user_id int

ID of the user to share with

required
access_level AccountAccess_v1

Access level (AccountAccess_v1 enum)

required

Returns:

Type Description
dict

Dictionary payload for v1 share API

Example

payload = generate_share_account_v1_payload( ... user_id=12345, ... access_level=AccountAccess_v1.CAN_VIEW ... )

Returns: {"type": "USER", "id": 12345, "permissions": ["READ"]}

Source code in src/crew_dcs/routes/account/access.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def generate_share_account_v1_payload(
    user_id: int,
    access_level: AccountAccess_v1,
) -> dict:
    """Generate v1 API sharing payload for users only.

    V1 API limitations:
    - Only supports sharing with users (no groups)
    - Limited permission set: READ, WRITE, OWNER

    Args:
        user_id: ID of the user to share with
        access_level: Access level (AccountAccess_v1 enum)

    Returns:
        Dictionary payload for v1 share API

    Example:
        >>> payload = generate_share_account_v1_payload(
        ...     user_id=12345,
        ...     access_level=AccountAccess_v1.CAN_VIEW
        ... )
        >>> # Returns: {"type": "USER", "id": 12345, "permissions": ["READ"]}
    """
    return {"type": "USER", "id": int(user_id), "permissions": [access_level.value]}

generate_share_account_v2_payload

generate_share_account_v2_payload(
    access_level: AccountAccess,
    user_id: int | None = None,
    group_id: int | None = None,
) -> dict

Generate v2 API sharing payload for users or groups.

V2 API features: - Supports both users and groups - Extended permissions: CAN_VIEW, CAN_EDIT, CAN_SHARE, OWNER, NO_ACCESS

Parameters:

Name Type Description Default
access_level AccountAccess

Access level (AccountAccess enum)

required
user_id int | None

ID of the user to share with (mutually exclusive with group_id)

None
group_id int | None

ID of the group to share with (mutually exclusive with user_id)

None

Returns:

Type Description
dict

Dictionary payload for v2 share API

Raises:

Type Description
ValueError

If neither or both user_id and group_id are provided

Example

payload = generate_share_account_v2_payload( ... access_level=AccountAccess.CAN_VIEW, ... user_id=12345 ... )

Returns: {"type": "USER", "id": "12345", "accessLevel": "CAN_VIEW"}

Source code in src/crew_dcs/routes/account/access.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
def generate_share_account_v2_payload(
    access_level: AccountAccess,
    user_id: int | None = None,
    group_id: int | None = None,
) -> dict:
    """Generate v2 API sharing payload for users or groups.

    V2 API features:
    - Supports both users and groups
    - Extended permissions: CAN_VIEW, CAN_EDIT, CAN_SHARE, OWNER, NO_ACCESS

    Args:
        access_level: Access level (AccountAccess enum)
        user_id: ID of the user to share with (mutually exclusive with group_id)
        group_id: ID of the group to share with (mutually exclusive with user_id)

    Returns:
        Dictionary payload for v2 share API

    Raises:
        ValueError: If neither or both user_id and group_id are provided

    Example:
        >>> payload = generate_share_account_v2_payload(
        ...     access_level=AccountAccess.CAN_VIEW,
        ...     user_id=12345
        ... )
        >>> # Returns: {"type": "USER", "id": "12345", "accessLevel": "CAN_VIEW"}
    """
    if not user_id and not group_id:
        raise ValueError("Must provide either user_id or group_id")

    if user_id and group_id:
        raise ValueError("Cannot provide both user_id and group_id")

    if user_id:
        return {"type": "USER", "id": str(user_id), "accessLevel": access_level.value}

    return {"type": "GROUP", "id": int(group_id), "accessLevel": access_level.value}

get_account_accesslist async

get_account_accesslist(
    auth: DomoAuth,
    account_id: str,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs
) -> ResponseGetData

Get access list for an account.

Parameters:

Name Type Description Default
auth DomoAuth

Authentication object for API requests

required
account_id str

ID of the account to get access list for

required
return_raw bool

Return raw response without processing

False
context RouteContext | None

RouteContext for request configuration

None

Returns:

Type Description
ResponseGetData

ResponseGetData object containing account access list

Raises:

Type Description
AccountSharing_Error

If access list retrieval fails

Source code in src/crew_dcs/routes/account/access.py
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
277
278
279
280
281
282
@gd.route_function
@log_call(
    level_name="route",
    config=LogDecoratorConfig(result_processor=ResponseGetDataProcessor()),
)
async def get_account_accesslist(
    auth: DomoAuth,
    account_id: str,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> rgd.ResponseGetData:
    """Get access list for an account.

    Args:
        auth: Authentication object for API requests
        account_id: ID of the account to get access list for
        return_raw: Return raw response without processing
        context: RouteContext for request configuration

    Returns:
        ResponseGetData object containing account access list

    Raises:
        AccountSharing_Error: If access list retrieval fails
    """

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

    url = (
        f"https://{auth.domo_instance}.domo.com/api/data/v2/accounts/share/{account_id}"
    )

    res = await gd.get_data(
        auth=auth,
        url=url,
        method="GET",
        context=context,
    )

    if return_raw:
        return res

    if not res.is_success:
        raise AccountSharing_Error(
            operation="get access list", account_id=account_id, res=res
        )

    res.response = res.response["list"]

    return res

get_oauth_account_accesslist async

get_oauth_account_accesslist(
    auth: DomoAuth,
    account_id: str,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs
) -> ResponseGetData

Get access list for an OAuth account.

Parameters:

Name Type Description Default
auth DomoAuth

Authentication object for API requests

required
account_id str

ID of the OAuth account to get access list for

required
return_raw bool

Return raw response without processing

False
context RouteContext | None

RouteContext for request configuration

None

Returns:

Type Description
ResponseGetData

ResponseGetData object containing OAuth account access list

Raises:

Type Description
AccountSharing_Error

If OAuth access list retrieval fails

Source code in src/crew_dcs/routes/account/access.py
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
320
321
322
323
324
325
326
327
328
329
330
331
332
@gd.route_function
@log_call(
    level_name="route",
    config=LogDecoratorConfig(result_processor=ResponseGetDataProcessor()),
)
async def get_oauth_account_accesslist(
    auth: DomoAuth,
    account_id: str,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> rgd.ResponseGetData:
    """Get access list for an OAuth account.

    Args:
        auth: Authentication object for API requests
        account_id: ID of the OAuth account to get access list for
        return_raw: Return raw response without processing
        context: RouteContext for request configuration

    Returns:
        ResponseGetData object containing OAuth account access list

    Raises:
        AccountSharing_Error: If OAuth access list retrieval fails
    """

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

    url = f"https://{auth.domo_instance}.domo.com/api/data/v2/accounts/templates/{account_id}/share"

    res = await gd.get_data(
        auth=auth,
        url=url,
        method="GET",
        context=context,
    )

    if return_raw:
        return res

    if not res.is_success:
        raise AccountSharing_Error(
            operation="get OAuth access list", account_id=account_id, res=res
        )

    return res

share_account async

share_account(
    auth: DomoAuth,
    account_id: str,
    share_payload: dict | None = None,
    access_level: (
        Access | AccountAccess_v1 | str | None
    ) = None,
    user_id: int | None = None,
    group_id: int | None = None,
    use_v1_api: bool = False,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs
) -> ResponseGetData

Share account with users/groups using v2 API.

Note: This uses the v2 API which should be deployed to all Domo instances as of DP24.

Two ways to call this function: 1. Pass pre-built share_payload (legacy mode) 2. Pass access_level with user_id or group_id (generates payload automatically)

Parameters:

Name Type Description Default
auth DomoAuth

Authentication object for API requests

required
account_id str

ID of the account to share

required
share_payload dict | None

Pre-built sharing payload (optional, overrides other params)

None
access_level Access | AccountAccess_v1 | str | None

Access level enum or string (required if share_payload not provided)

None
user_id int | None

ID of user to share with (mutually exclusive with group_id)

None
group_id int | None

ID of group to share with (mutually exclusive with user_id)

None
use_v1_api bool

Force v1 API usage (ignored if group_id provided)

False
return_raw bool

Return raw response without processing

False
context RouteContext | None

RouteContext for request configuration

None

Returns:

Type Description
ResponseGetData

ResponseGetData object confirming sharing operation

Raises:

Type Description
ValueError

If neither share_payload nor access_level provided

Account_AlreadyShared_Error

If account is already shared with target

Account_Share_Error

If sharing operation fails

Examples:

>>> # Using payload generator (new way)
>>> await share_account(
...     auth=auth,
...     account_id="123",
...     access_level=ShareAccount_AccessLevel.CAN_VIEW,
...     user_id=456
... )
>>> # Using pre-built payload (legacy way)
>>> payload = generate_share_account_v2_payload(
...     access_level=ShareAccount_AccessLevel.CAN_VIEW,
...     group_id=789
... )
>>> await share_account(
...     auth=auth,
...     account_id="123",
...     share_payload=payload
... )
Source code in src/crew_dcs/routes/account/access.py
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
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
@gd.route_function
@log_call(
    level_name="route",
    config=LogDecoratorConfig(result_processor=ResponseGetDataProcessor()),
)
async def share_account(
    auth: DomoAuth,
    account_id: str,
    share_payload: dict | None = None,
    access_level: Access | AccountAccess_v1 | str | None = None,
    user_id: int | None = None,
    group_id: int | None = None,
    use_v1_api: bool = False,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> rgd.ResponseGetData:
    """Share account with users/groups using v2 API.

    Note: This uses the v2 API which should be deployed to all Domo instances as of DP24.

    Two ways to call this function:
    1. Pass pre-built share_payload (legacy mode)
    2. Pass access_level with user_id or group_id (generates payload automatically)

    Args:
        auth: Authentication object for API requests
        account_id: ID of the account to share
        share_payload: Pre-built sharing payload (optional, overrides other params)
        access_level: Access level enum or string (required if share_payload not provided)
        user_id: ID of user to share with (mutually exclusive with group_id)
        group_id: ID of group to share with (mutually exclusive with user_id)
        use_v1_api: Force v1 API usage (ignored if group_id provided)
        return_raw: Return raw response without processing
        context: RouteContext for request configuration

    Returns:
        ResponseGetData object confirming sharing operation

    Raises:
        ValueError: If neither share_payload nor access_level provided
        Account_AlreadyShared_Error: If account is already shared with target
        Account_Share_Error: If sharing operation fails

    Examples:
        >>> # Using payload generator (new way)
        >>> await share_account(
        ...     auth=auth,
        ...     account_id="123",
        ...     access_level=ShareAccount_AccessLevel.CAN_VIEW,
        ...     user_id=456
        ... )

        >>> # Using pre-built payload (legacy way)
        >>> payload = generate_share_account_v2_payload(
        ...     access_level=ShareAccount_AccessLevel.CAN_VIEW,
        ...     group_id=789
        ... )
        >>> await share_account(
        ...     auth=auth,
        ...     account_id="123",
        ...     share_payload=payload
        ... )
    """

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

    # Generate payload if not provided
    if not share_payload:
        if not access_level:
            raise ValueError("Must provide either share_payload or access_level")

        share_payload = generate_share_account_payload(
            access_level=access_level,
            user_id=user_id,
            group_id=group_id,
            use_v1_api=use_v1_api,
        )

    # Route to appropriate API endpoint
    if use_v1_api or (access_level and isinstance(access_level, AccountAccess_v1)):
        # Use v1 endpoint
        url = f"https://{auth.domo_instance}.domo.com/api/data/v1/accounts/{account_id}/share"
    else:
        # Use v2 endpoint
        url = f"https://{auth.domo_instance}.domo.com/api/data/v2/accounts/share/{account_id}"

    method = "PUT"

    res = await gd.get_data(
        auth=auth,
        url=url,
        method=method,
        body=share_payload,
        context=context,
    )

    if return_raw:
        return res

    if res.status == 500 and res.response == "Internal Server Error":
        raise AccountSharing_Error(
            account_id=account_id,
            message=f"{res.response} - User may already have access to account",
            res=res,
            operation=method,
        )

    if not res.is_success:
        raise AccountSharing_Error(account_id=account_id, res=res, operation=method)

    return res

share_account_v1 async

share_account_v1(
    auth: DomoAuth,
    account_id: str,
    share_payload: dict | None = None,
    access_level: AccountAccess_v1 | str | None = None,
    user_id: int | None = None,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs
) -> ResponseGetData

Share account using legacy v1 API (users only).

Note: V1 API allows sharing with users ONLY. It does not support sharing with groups and has a more limited set of share rights (owner or read). See AccountAccess_v1 vs AccountAccess for differences.

Two ways to call this function: 1. Pass pre-built share_payload (legacy mode) 2. Pass access_level with user_id (generates payload automatically)

Parameters:

Name Type Description Default
auth DomoAuth

Authentication object for API requests

required
account_id str

ID of the account to share

required
share_payload dict | None

Pre-built sharing payload (optional, overrides other params)

None
access_level AccountAccess_v1 | str | None

Access level enum or string (required if share_payload not provided)

None
user_id int | None

ID of user to share with (required if share_payload not provided)

None
return_raw bool

Return raw response without processing

False
context RouteContext | None

RouteContext for request configuration

None

Returns:

Type Description
ResponseGetData

ResponseGetData object confirming sharing operation

Raises:

Type Description
ValueError

If neither share_payload nor (access_level and user_id) provided

Account_AlreadyShared_Error

If account is already shared with user

Account_Share_Error

If sharing operation fails

Examples:

>>> # Using payload generator
>>> await share_account_v1(
...     auth=auth,
...     account_id="123",
...     access_level=ShareAccount_V1_AccessLevel.CAN_VIEW,
...     user_id=456
... )
Source code in src/crew_dcs/routes/account/access.py
536
537
538
539
540
541
542
543
544
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
578
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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
@gd.route_function
@log_call(
    level_name="route",
    config=LogDecoratorConfig(result_processor=ResponseGetDataProcessor()),
)
async def share_account_v1(
    auth: DomoAuth,
    account_id: str,
    share_payload: dict | None = None,
    access_level: AccountAccess_v1 | str | None = None,
    user_id: int | None = None,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> rgd.ResponseGetData:
    """Share account using legacy v1 API (users only).

    Note: V1 API allows sharing with users ONLY. It does not support sharing with groups
    and has a more limited set of share rights (owner or read). See AccountAccess_v1
    vs AccountAccess for differences.

    Two ways to call this function:
    1. Pass pre-built share_payload (legacy mode)
    2. Pass access_level with user_id (generates payload automatically)

    Args:
        auth: Authentication object for API requests
        account_id: ID of the account to share
        share_payload: Pre-built sharing payload (optional, overrides other params)
        access_level: Access level enum or string (required if share_payload not provided)
        user_id: ID of user to share with (required if share_payload not provided)
        return_raw: Return raw response without processing
        context: RouteContext for request configuration

    Returns:
        ResponseGetData object confirming sharing operation

    Raises:
        ValueError: If neither share_payload nor (access_level and user_id) provided
        Account_AlreadyShared_Error: If account is already shared with user
        Account_Share_Error: If sharing operation fails

    Examples:
        >>> # Using payload generator
        >>> await share_account_v1(
        ...     auth=auth,
        ...     account_id="123",
        ...     access_level=ShareAccount_V1_AccessLevel.CAN_VIEW,
        ...     user_id=456
        ... )
    """

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

    # Generate payload if not provided
    if not share_payload:
        if not access_level or not user_id:
            raise ValueError(
                "Must provide either share_payload or (access_level and user_id)"
            )

        share_payload = generate_share_account_v1_payload(
            user_id=user_id,
            access_level=access_level,
        )

    url = (
        f"https://{auth.domo_instance}.domo.com/api/data/v1/accounts/{account_id}/share"
    )

    res = await gd.get_data(
        auth=auth,
        url=url,
        method="PUT",
        body=share_payload,
        context=context,
    )

    if return_raw:
        return res

    if res.status == 500 and res.response == "Internal Server Error":
        raise AccountSharing_Error(
            account_id=account_id,
            message=f"{res.response} - User may already have access to account",
            res=res,
            operation="PUT",
        )

    if not res.is_success:
        raise AccountSharing_Error(
            account_id=account_id,
            res=res,
            operation="PUT",
        )

    return res

share_oauth_account async

share_oauth_account(
    auth: DomoAuth,
    account_id: str,
    share_payload: dict | None = None,
    access_level: Access | str | None = None,
    user_id: int | None = None,
    group_id: int | None = None,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs
) -> ResponseGetData

Share OAuth account with users/groups.

Two ways to call this function: 1. Pass pre-built share_payload (legacy mode) 2. Pass access_level with user_id or group_id (generates payload automatically)

Parameters:

Name Type Description Default
auth DomoAuth

Authentication object for API requests

required
account_id str

ID of the OAuth account to share

required
share_payload dict | None

Pre-built sharing payload (optional, overrides other params)

None
access_level Access | str | None

Access level enum or string (required if share_payload not provided)

None
user_id int | None

ID of user to share with (mutually exclusive with group_id)

None
group_id int | None

ID of group to share with (mutually exclusive with user_id)

None
return_raw bool

Return raw response without processing

False
context RouteContext | None

RouteContext for request configuration

None

Returns:

Type Description
ResponseGetData

ResponseGetData object confirming sharing operation

Raises:

Type Description
ValueError

If neither share_payload nor access_level provided

Account_Share_Error

If OAuth sharing operation fails

Examples:

>>> # Using payload generator
>>> await share_oauth_account(
...     auth=auth,
...     account_id="123",
...     access_level=ShareAccount_AccessLevel.CAN_VIEW,
...     group_id=789
... )
Source code in src/crew_dcs/routes/account/access.py
450
451
452
453
454
455
456
457
458
459
460
461
462
463
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
490
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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
@gd.route_function
@log_call(
    level_name="route",
    config=LogDecoratorConfig(result_processor=ResponseGetDataProcessor()),
)
async def share_oauth_account(
    auth: DomoAuth,
    account_id: str,
    share_payload: dict | None = None,
    access_level: Access | str | None = None,
    user_id: int | None = None,
    group_id: int | None = None,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> rgd.ResponseGetData:
    """Share OAuth account with users/groups.

    Two ways to call this function:
    1. Pass pre-built share_payload (legacy mode)
    2. Pass access_level with user_id or group_id (generates payload automatically)

    Args:
        auth: Authentication object for API requests
        account_id: ID of the OAuth account to share
        share_payload: Pre-built sharing payload (optional, overrides other params)
        access_level: Access level enum or string (required if share_payload not provided)
        user_id: ID of user to share with (mutually exclusive with group_id)
        group_id: ID of group to share with (mutually exclusive with user_id)
        return_raw: Return raw response without processing
        context: RouteContext for request configuration

    Returns:
        ResponseGetData object confirming sharing operation

    Raises:
        ValueError: If neither share_payload nor access_level provided
        Account_Share_Error: If OAuth sharing operation fails

    Examples:
        >>> # Using payload generator
        >>> await share_oauth_account(
        ...     auth=auth,
        ...     account_id="123",
        ...     access_level=ShareAccount_AccessLevel.CAN_VIEW,
        ...     group_id=789
        ... )
    """

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

    # Generate payload if not provided
    if not share_payload:
        if not access_level:
            raise ValueError("Must provide either share_payload or access_level")

        share_payload = generate_share_account_v2_payload(
            access_level=access_level,
            user_id=user_id,
            group_id=group_id,
        )

    url = f"https://{auth.domo_instance}.domo.com/api/data/v2/accounts/templates/share/{account_id}"

    res = await gd.get_data(
        auth=auth,
        url=url,
        method="PUT",
        body=share_payload,
        context=context,
    )

    if return_raw:
        return res

    if not res.is_success:
        raise AccountSharing_Error(
            account_id=account_id,
            res=res,
            operation="share OAuth account",
        )

    return res