Skip to content

create_user

create_user(
    organization_id: OrganizationId,
    name: UserName,
    display_name: UserAttribute,
    *,
    config_overrides: Optional[WorkMailClientConfig] = None,
    password: Optional[Password] = None,
    role: Optional[UserRole] = None,
    first_name: Optional[UserAttribute] = None,
    last_name: Optional[UserAttribute] = None,
    hidden_from_global_address_list: Optional[Boolean] = None,
    identity_provider_user_id: Optional[IdentityProviderUserId] = None,
) -> CreateUserResponse

Creates a user who can be used in WorkMail by calling the RegisterToWorkMail operation.

Parameters:

  • organization_id (OrganizationId) –

    The identifier of the organization for which the user is created.

  • name (UserName) –

    The name for the new user. WorkMail directory user names have a maximum length of 64. All others have a maximum length of 20.

  • display_name (UserAttribute) –

    The display name for the new user.

  • password (Optional[Password], default: None ) –

    The password for the new user.

  • role (Optional[UserRole], default: None ) –

    The role of the new user.

    You cannot pass SYSTEM_USER or RESOURCE role in a single request. When a user role is not selected, the default role of USER is selected.

  • first_name (Optional[UserAttribute], default: None ) –

    The first name of the new user.

  • last_name (Optional[UserAttribute], default: None ) –

    The last name of the new user.

  • hidden_from_global_address_list (Optional[Boolean], default: None ) –

    If this parameter is enabled, the user will be hidden from the address book.

  • identity_provider_user_id (Optional[IdentityProviderUserId], default: None ) –

    User ID from the IAM Identity Center. If this parameter is empty it will be updated automatically when the user logs in for the first time to the mailbox associated with WorkMail.

Raises:

Source code in docs_src/capo_workmail/_services/work_mail.py
def create_user(
    self,
    organization_id: "capo_workmail.types.organization_id.OrganizationId",
    name: "capo_workmail.types.user_name.UserName",
    display_name: "capo_workmail.types.user_attribute.UserAttribute",
    *,
    config_overrides: Optional[WorkMailClientConfig] = None,
    password: Optional["capo_workmail.types.password.Password"] = None,
    role: Optional["capo_workmail.types.user_role.UserRole"] = None,
    first_name: Optional["capo_workmail.types.user_attribute.UserAttribute"] = None,
    last_name: Optional["capo_workmail.types.user_attribute.UserAttribute"] = None,
    hidden_from_global_address_list: Optional[
        "capo_workmail.types.boolean.Boolean"
    ] = None,
    identity_provider_user_id: Optional[
        "capo_workmail.types.identity_provider_user_id.IdentityProviderUserId"
    ] = None,
) -> "capo_workmail.types.create_user_response.CreateUserResponse":
    """<p>Creates a user who can be used in WorkMail by calling the <a>RegisterToWorkMail</a> operation.</p>

    Args:
        organization_id: <p>The identifier of the organization for which the user is created.</p>
        name: <p>The name for the new user. WorkMail directory user names have a maximum length of 64. All others have a maximum length of 20.</p>
        display_name: <p>The display name for the new user.</p>
        password: <p>The password for the new user.</p>
        role: <p>The role of the new user.</p> <p>You cannot pass <i>SYSTEM_USER</i> or <i>RESOURCE</i> role in a single request. When a user role is not selected, the default role of <i>USER</i> is selected.</p>
        first_name: <p>The first name of the new user.</p>
        last_name: <p>The last name of the new user. </p>
        hidden_from_global_address_list: <p>If this parameter is enabled, the user will be hidden from the address book.</p>
        identity_provider_user_id: <p>User ID from the IAM Identity Center. If this parameter is empty it will be updated automatically when the user logs in for the first time to the mailbox associated with WorkMail.</p>

    Raises:
        capo_workmail.errors.directory_service_authentication_failed_exception.DirectoryServiceAuthenticationFailedException: <p>The directory service doesn't recognize the credentials supplied by WorkMail.</p>
        capo_workmail.errors.directory_unavailable_exception.DirectoryUnavailableException: <p>The directory is unavailable. It might be located in another Region or deleted.</p>
        capo_workmail.errors.invalid_parameter_exception.InvalidParameterException: <p>One or more of the input parameters don't match the service's restrictions.</p>
        capo_workmail.errors.invalid_password_exception.InvalidPasswordException: <p>The supplied password doesn't match the minimum security constraints, such as length or use of special characters.</p>
        capo_workmail.errors.name_availability_exception.NameAvailabilityException: <p>The user, group, or resource name isn't unique in WorkMail.</p>
        capo_workmail.errors.organization_not_found_exception.OrganizationNotFoundException: <p>An operation received a valid organization identifier that either doesn't belong or exist in the system.</p>
        capo_workmail.errors.organization_state_exception.OrganizationStateException: <p>The organization must have a valid state to perform certain operations on the organization or its members.</p>
        capo_workmail.errors.reserved_name_exception.ReservedNameException: <p>This user, group, or resource name is not allowed in WorkMail.</p>
        capo_workmail.errors.unsupported_operation_exception.UnsupportedOperationException: <p>You can't perform a write operation against a read-only directory.</p>
        capo_workmail.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_workmail.types.create_user_request.CreateUserRequest]",
    ) -> OperationResponse[
        "capo_workmail.types.create_user_response.CreateUserResponse"
    ]:
        import capo_workmail._operations.work_mail_service.create_user

        output, http_response = (
            capo_workmail._operations.work_mail_service.create_user.create_user(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_workmail.types.create_user_request.CreateUserRequest",
    ) -> dict[str, Any]:
        import capo_workmail.types.create_user_request

        return capo_workmail.types.create_user_request.redact_sensitive(input_)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateUser", redact_input=_redact_input)
    )
    input_: capo_workmail.types.create_user_request.CreateUserRequest = {
        "organization_id": organization_id,
        "name": name,
        "display_name": display_name,
    }
    if password is not None:
        input_["password"] = password
    if role is not None:
        input_["role"] = role
    if first_name is not None:
        input_["first_name"] = first_name
    if last_name is not None:
        input_["last_name"] = last_name
    if hidden_from_global_address_list is not None:
        input_["hidden_from_global_address_list"] = hidden_from_global_address_list
    if identity_provider_user_id is not None:
        input_["identity_provider_user_id"] = identity_provider_user_id

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output