Search code examples
outlookoffice365exchangewebservices

How to create an EWS item (Calendar event or Contact) in the Deleted Items folder in Outlook?


I was trying to recreate the item into Deleted Items folder, but nothing happened, I got these errors "ErrorCannotCreateCalendarItemInNonCalendarFolder" or "ErrorCannotCreateContactInNonContactFolder". How to overcome this?

I used the request to POST with the body

    "<?xml version=\"1.0\" encoding=\"utf-8\"?> "
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "
                   "xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" >"
      "<soap:Header> "
        "<t:RequestServerVersion Version=\"Exchange2013\" /> "
        "<t:ExchangeImpersonation> "
          "<t:ConnectingSID> "
            "<t:PrincipalName>%MAIL_BOX%</t:PrincipalName> "     // <<------- MAIL_BOX ---- FILLED IN BY A TEMPLATE PARAM
          "</t:ConnectingSID> "
        "</t:ExchangeImpersonation> "
      "</soap:Header> "
      "<soap:Body> "
        "<CreateItem xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\" "
                    "MessageDisposition=\"SaveOnly\" "
                    "SendMeetingInvitations=\"SendToNone\"> "
          "<SavedItemFolderId>"
            "<t:FolderId Id=\"%FOLDER_ID%\"/>"                             // <<------- FOLDER_ID ---- FILLED IN BY A TEMPLATE PARAM
          "</SavedItemFolderId>"
          "<Items>"
            "%ITEMS_CONTENT%"                                              // <<------- ITEMS_CONTENT ---- FILLED IN BY A TEMPLATE PARAM
          "</Items>"
        "</CreateItem>"
      "</soap:Body>"
    "</soap:Envelope>";

And got such the response:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1922" MinorBuildNumber="23" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
    </s:Header>
    <s:Body>
        <m:CreateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
            <m:ResponseMessages>
                <m:CreateItemResponseMessage ResponseClass="Error">
                    <m:MessageText>Cannot create a calendar item in a non-calendar folder.</m:MessageText>
                    <m:ResponseCode>ErrorCannotCreateCalendarItemInNonCalendarFolder</m:ResponseCode>
                    <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
                    <m:Items />
                </m:CreateItemResponseMessage>
            </m:ResponseMessages>
        </m:CreateItemResponse>
    </s:Body>
</s:Envelope>

Solution

  • Because the Deleted Items Folder class is IPF.Note EWS restricts you from creating items that are Calendar or Contacts in these types of folder hence the error message your receiving. A workaround is just create the Items in the normal Calendar or Contacts folder and then use the Move operation to move it after you have created it.