CreateItems method

Future<ServiceResponseCollection<ServiceResponse>> CreateItems(
  1. Iterable<Item> items,
  2. FolderId? parentFolderId,
  3. MessageDisposition? messageDisposition,
  4. SendInvitationsMode? sendInvitationsMode,
)
Creates multiple items in a single EWS call. Supported item classes are EmailMessage, Appointment, Contact, PostItem, Task and Item. CreateItems does not support items that have unsaved attachments. The items to create. The Id of the folder in which to place the newly created items. If null, items are created in their default folders. Indicates the disposition mode for items of type EmailMessage. Required if items contains at least one EmailMessage instance. Indicates if and how invitations should be sent for items of type Appointment. Required if items contains at least one Appointment instance.

Implementation

Future<ServiceResponseCollection<ServiceResponse>> CreateItems(
  Iterable<Item> items,
  FolderId? parentFolderId,
  MessageDisposition? messageDisposition,
  SendInvitationsMode? sendInvitationsMode,
) {
  // All items have to be new.
  if (!items.every((item) => item.IsNew)) {
    throw ServiceValidationException(
      "This operation can't be performed because at least one item already has an ID.",
    );
  }

  // Make sure that all items do *not* have unprocessed attachments.
  if (!items.every((item) => !item.HasUnprocessedAttachmentChanges())) {
    throw ServiceValidationException(
      "This operation doesn't support items that have attachments.",
    );
  }

  return InternalCreateItems(
    items,
    parentFolderId,
    messageDisposition,
    sendInvitationsMode,
    ServiceErrorHandling.ReturnErrors,
  );
}