createUser method

Future<CreateUserResponse> createUser({
  1. required String displayName,
  2. required String name,
  3. required String organizationId,
  4. String? firstName,
  5. bool? hiddenFromGlobalAddressList,
  6. String? identityProviderUserId,
  7. String? lastName,
  8. String? password,
  9. UserRole? role,
})

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

May throw DirectoryServiceAuthenticationFailedException. May throw DirectoryUnavailableException. May throw InvalidParameterException. May throw InvalidPasswordException. May throw NameAvailabilityException. May throw OrganizationNotFoundException. May throw OrganizationStateException. May throw ReservedNameException. May throw UnsupportedOperationException.

Parameter displayName : The display name for the new user.

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

Parameter organizationId : The identifier of the organization for which the user is created.

Parameter firstName : The first name of the new user.

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

Parameter identityProviderUserId : 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.

Parameter lastName : The last name of the new user.

Parameter password : The password for the new user.

Parameter role : 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.

Implementation

Future<CreateUserResponse> createUser({
  required String displayName,
  required String name,
  required String organizationId,
  String? firstName,
  bool? hiddenFromGlobalAddressList,
  String? identityProviderUserId,
  String? lastName,
  String? password,
  UserRole? role,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'WorkMailService.CreateUser'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'DisplayName': displayName,
      'Name': name,
      'OrganizationId': organizationId,
      if (firstName != null) 'FirstName': firstName,
      if (hiddenFromGlobalAddressList != null)
        'HiddenFromGlobalAddressList': hiddenFromGlobalAddressList,
      if (identityProviderUserId != null)
        'IdentityProviderUserId': identityProviderUserId,
      if (lastName != null) 'LastName': lastName,
      if (password != null) 'Password': password,
      if (role != null) 'Role': role.value,
    },
  );

  return CreateUserResponse.fromJson(jsonResponse.body);
}