soapexchangewebservicesoutlook-addinoffice-jsoutlook-web-addins

MarkAsJunk operation Error Code 9020. Getting "An internal server error occurred. The operation failed."


I am trying to use the MarkAsJunk operation using only SOAP requests with Office.context.mailbox.makeEwsRequestAsync. For this purpose I also use the easyEWS module which is a wrapper over OfficeJS. The code I'm using to send the SOAP looks like this:

this.markAsJunk = function (itemId) {
    var soap = '<m:MarkAsJunk IsJunk="true" MoveItem="true"' +
            '          
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
            '    <ItemIds>' +
            '        <t:ItemId Id="' + itemId + '"/>' +
            '    </ItemIds>' +
            '</m:MarkAsJunk>';
    soap = getSoapHeader(soap);

    asyncEws(soap, function (data) { });
};

The SOAP which I'm sending looks like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
   <soap:Header>
        <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />
   </soap:Header>
   <soap:Body>
        <m:MarkAsJunk IsJunk="true" MoveItem="true"
        xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
            <ItemIds>
                <t:ItemId Id="AAMkADg2OGZmNDkzLWVjNDYtNGI2MC1iMGI3LWE3YmEzMDk5MThiNABGAAAAAAC3FQIsRYg6SZwlyqfCFdA0BwBTNDtA08+GRo/QPlH0XaGpAAAAAAEMAABTNDtA08+GRo/QPlH0XaGpAADEMDCVAAA="/>
            </ItemIds>
        </m:MarkAsJunk>
    </soap:Body>
</soap:Envelope>

Solution

  • ItemIds is present in namespace xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages", so you need to use "m:ItemIds". Please refer the tutorial here for the SOAP request format.