Skip to content

saved_scenario_users_create

saved_scenario_users_create

Service for saved scenario users create operations.

Classes

SavedScenarioUsersCreateRunner

Bases: BaseRunner[List[Dict[str, Any]]]

Runner for adding users to a SavedScenario.

POST /api/v3/saved_scenarios/:saved_scenario_id/users

Note

When a user is added to a saved scenario, they are also automatically added to: - The current scenario (via scenario_id) - All historical scenarios (via scenario_id_history)

Functions
run staticmethod
run(client, saved_scenario_id, users, **kwargs)

Add users to a saved scenario with specified roles.

Parameters:

Name Type Description Default
client BaseClient

The HTTP client to use

required
saved_scenario_id int

ID of the SavedScenario

required
users List[Dict[str, Any]]

List of user objects to add, each containing: - user_email: Email address (required) - role: User role - scenario_owner, scenario_collaborator, or scenario_viewer (required) - user_id: ID of existing user (optional, will be auto-coupled if email matches)

required
**kwargs Any

Additional arguments passed to the request

{}

Returns:

Type Description
ServiceResult[List[Dict[str, Any]]]

ServiceResult containing list of created user objects

Source code in src/pyetm/services/scenario_runners/saved_scenario_users_create.py
@staticmethod
def run(
    client: BaseClient,
    saved_scenario_id: int,
    users: List[Dict[str, Any]],
    **kwargs: Any,
) -> ServiceResult[List[Dict[str, Any]]]:
    """
    Add users to a saved scenario with specified roles.

    Args:
        client: The HTTP client to use
        saved_scenario_id: ID of the SavedScenario
        users: List of user objects to add, each containing:
            - user_email: Email address (required)
            - role: User role - scenario_owner, scenario_collaborator, or scenario_viewer (required)
            - user_id: ID of existing user (optional, will be auto-coupled if email matches)
        **kwargs: Additional arguments passed to the request

    Returns:
        ServiceResult containing list of created user objects
    """
    if not users:
        return ServiceResult.fail(["No users provided"])

    errors = []
    for i, user in enumerate(users):
        missing = SavedScenarioUsersCreateRunner._validate_required_fields(
            user, SavedScenarioUsersCreateRunner.REQUIRED_KEYS
        )
        if missing:
            errors.extend([f"User {i}: {err}" for err in missing])

    if errors:
        return ServiceResult.fail(errors)

    payload = {"saved_scenario_users": users}

    return SavedScenarioUsersCreateRunner._make_request(
        client=client,
        method="post",
        path=f"/saved_scenarios/{saved_scenario_id}/users",
        payload=payload,
        **kwargs,
    )