createContact method

Future<void> createContact({
  1. required String contactListName,
  2. required String emailAddress,
  3. String? attributesData,
  4. List<TopicPreference>? topicPreferences,
  5. bool? unsubscribeAll,
})

Creates a contact, which is an end-user who is receiving the email, and adds them to a contact list.

May throw BadRequestException. May throw TooManyRequestsException. May throw NotFoundException. May throw AlreadyExistsException.

Parameter contactListName : The name of the contact list to which the contact should be added.

Parameter emailAddress : The contact's email address.

Parameter attributesData : The attribute data attached to a contact.

Parameter topicPreferences : The contact's preferences for being opted-in to or opted-out of topics.

Parameter unsubscribeAll : A boolean value status noting if the contact is unsubscribed from all contact list topics.

Implementation

Future<void> createContact({
  required String contactListName,
  required String emailAddress,
  String? attributesData,
  List<TopicPreference>? topicPreferences,
  bool? unsubscribeAll,
}) async {
  ArgumentError.checkNotNull(contactListName, 'contactListName');
  ArgumentError.checkNotNull(emailAddress, 'emailAddress');
  final $payload = <String, dynamic>{
    'EmailAddress': emailAddress,
    if (attributesData != null) 'AttributesData': attributesData,
    if (topicPreferences != null) 'TopicPreferences': topicPreferences,
    if (unsubscribeAll != null) 'UnsubscribeAll': unsubscribeAll,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri:
        '/v2/email/contact-lists/${Uri.encodeComponent(contactListName)}/contacts',
    exceptionFnMap: _exceptionFns,
  );
}