createContact method

Future<CreateContactResponse> createContact({
  1. required String firstName,
  2. String? clientRequestToken,
  3. String? displayName,
  4. String? lastName,
  5. String? phoneNumber,
  6. List<PhoneNumber>? phoneNumbers,
  7. List<SipAddress>? sipAddresses,
})

Creates a contact with the specified details.

May throw AlreadyExistsException. May throw LimitExceededException.

Parameter firstName : The first name of the contact that is used to call the contact on the device.

Parameter clientRequestToken : A unique, user-specified identifier for this request that ensures idempotency.

Parameter displayName : The name of the contact to display on the console.

Parameter lastName : The last name of the contact that is used to call the contact on the device.

Parameter phoneNumber : The phone number of the contact in E.164 format. The phone number type defaults to WORK. You can specify PhoneNumber or PhoneNumbers. We recommend that you use PhoneNumbers, which lets you specify the phone number type and multiple numbers.

Parameter phoneNumbers : The list of phone numbers for the contact.

Parameter sipAddresses : The list of SIP addresses for the contact.

Implementation

Future<CreateContactResponse> createContact({
  required String firstName,
  String? clientRequestToken,
  String? displayName,
  String? lastName,
  String? phoneNumber,
  List<PhoneNumber>? phoneNumbers,
  List<SipAddress>? sipAddresses,
}) async {
  ArgumentError.checkNotNull(firstName, 'firstName');
  _s.validateStringLength(
    'firstName',
    firstName,
    1,
    100,
    isRequired: true,
  );
  _s.validateStringLength(
    'clientRequestToken',
    clientRequestToken,
    10,
    150,
  );
  _s.validateStringLength(
    'displayName',
    displayName,
    1,
    100,
  );
  _s.validateStringLength(
    'lastName',
    lastName,
    1,
    100,
  );
  _s.validateStringLength(
    'phoneNumber',
    phoneNumber,
    0,
    50,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AlexaForBusiness.CreateContact'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'FirstName': firstName,
      'ClientRequestToken':
          clientRequestToken ?? _s.generateIdempotencyToken(),
      if (displayName != null) 'DisplayName': displayName,
      if (lastName != null) 'LastName': lastName,
      if (phoneNumber != null) 'PhoneNumber': phoneNumber,
      if (phoneNumbers != null) 'PhoneNumbers': phoneNumbers,
      if (sipAddresses != null) 'SipAddresses': sipAddresses,
    },
  );

  return CreateContactResponse.fromJson(jsonResponse.body);
}