createUser method

Future<CreateUserResult> createUser({
  1. required String directoryId,
  2. required String sAMAccountName,
  3. String? clientToken,
  4. String? emailAddress,
  5. String? givenName,
  6. Map<String, AttributeValue>? otherAttributes,
  7. String? surname,
})

Creates a new user.

May throw AccessDeniedException. May throw ConflictException. May throw DirectoryUnavailableException. May throw InternalServerException. May throw ThrottlingException. May throw ValidationException.

Parameter directoryId : The identifier (ID) of the directory that’s associated with the user.

Parameter sAMAccountName : The name of the user.

Parameter clientToken : A unique and case-sensitive identifier that you provide to make sure the idempotency of the request, so multiple identical calls have the same effect as one single call.

A client token is valid for 8 hours after the first request that uses it completes. After 8 hours, any request with the same client token is treated as a new request. If the request succeeds, any future uses of that token will be idempotent for another 8 hours.

If you submit a request with the same client token but change one of the other parameters within the 8-hour idempotency window, Directory Service Data returns an ConflictException.

Parameter emailAddress : The email address of the user.

Parameter givenName : The first name of the user.

Parameter otherAttributes : An expression that defines one or more attribute names with the data type and value of each attribute. A key is an attribute name, and the value is a list of maps. For a list of supported attributes, see Directory Service Data Attributes.

Parameter surname : The last name of the user.

Implementation

Future<CreateUserResult> createUser({
  required String directoryId,
  required String sAMAccountName,
  String? clientToken,
  String? emailAddress,
  String? givenName,
  Map<String, AttributeValue>? otherAttributes,
  String? surname,
}) async {
  final $query = <String, List<String>>{
    'DirectoryId': [directoryId],
  };
  final $payload = <String, dynamic>{
    'SAMAccountName': sAMAccountName,
    'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
    if (emailAddress != null) 'EmailAddress': emailAddress,
    if (givenName != null) 'GivenName': givenName,
    if (otherAttributes != null) 'OtherAttributes': otherAttributes,
    if (surname != null) 'Surname': surname,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/Users/CreateUser',
    queryParams: $query,
    exceptionFnMap: _exceptionFns,
  );
  return CreateUserResult.fromJson(response);
}