1
votes

My outlook addin uses "ReadWriteMailbox" permission. I am trying to use makeEwsRequestAsync method and send a EWS "MoveItem" request to move the message to a specific folder. But i am getting the following errror,

"The EWS Id is in EwsLegacyId format which is not supported by the Exchange version specified by your request. Please use the ConvertId method to convert the Id from EwsId to EwsLegacyId format."

Request Sent

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"              
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"              
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"               
 xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">  
<soap:Header> 
    <RequestServerVersion Version="Exchange2013" /> 
</soap:Header>  
<soap:Body>   
<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">     
    <ToFolderId>
        <t:FolderId Id="AAAbAEJhbGFrcmlzaG5hbl9SQHN5bWFudGVjLmNvbQAuAAAAAACALDzcpfeRQ7ZlsoKB0iVmAQAjK9sGaxZsQpt2dmaMGjhaAADb64+wAAA="  ChangeKey="AQAAABYAAAAjK9sGaxZsQpt2dmaMGjhaAADcIrnw"/> 
    </ToFolderId>     
    <ItemIds>
        <t:ItemId Id="AAMkAGJiNjY2ZTk1LTZkMDEtNGQyYy05M2M2LWMyZmQwMzY1M2JhMQBGAAAAAACALDzcpfeRQ7ZlsoKB0iVmBwArZr3QPuquTIplat84SmYEAEq/mAl5AAAjK9sGaxZsQpt2dmaMGjhaAADb62uqAAA="/>
    </ItemIds>   
</MoveItem> 
</soap:Body>
</soap:Envelope>

Response Received

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="1075" MinorBuildNumber="20" 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:MoveItemResponse 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:MoveItemResponseMessage ResponseClass="Error">
                    <m:MessageText>The EWS Id is in EwsLegacyId format which is not supported by the Exchange version specified by your request. Please use the ConvertId method to convert the Id from EwsId to EwsLegacyId  format.
                    </m:MessageText>
                    <m:ResponseCode>ErrorInvalidIdMalformed</m:ResponseCode>
                    <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
                    <m:Items/>
                </m:MoveItemResponseMessage>
            </m:ResponseMessages>
        </m:MoveItemResponse>
    </s:Body>
</s:Envelope>

I am able to use the MoveItem EWS operation and move the messages to "Junk Email" folder. But i want to move messages to a specific folder created by a earlier "CreateFolder" EWS operation. The id of the folder is "AAAbAEJhbGFrcmlzaG5hbl9SQHN5bWFudGVjLmNvbQAuAAAAAACALDzcpfeRQ7ZlsoKB0iVmAQAjK9sGaxZsQpt2dmaMGjhaAADb64+wAAA="

Using the above id in "GetFolder" operation correctly returns the no. of items in the folder. But I am not able to get the "MoveItem" operation to work. All the EWS operations are performed via the "makeEwsRequestAsync" call. Could you help with this?

Updates

CreateFolder Request:

<?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:soap="http://schemas.xmlsoap.org/soap/envelope/"        
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header> 
    <RequestServerVersion Version="Exchange2013" /> 
</soap:Header>  
<soap:Body>  
    <CreateFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">          
        <ParentFolderId><t:DistinguishedFolderId Id="msgfolderroot"/></ParentFolderId>           <Folders><t:Folder><t:DisplayName>Submissions</t:DisplayName></t:Folder></Folders>    
    </CreateFolder>  
</soap:Body>
</soap:Envelope>

Create Folder 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="1" MajorBuildNumber="1075" MinorBuildNumber="21" 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:CreateFolderResponse 
    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:CreateFolderResponseMessage ResponseClass="Success">
        <m:ResponseCode>NoError</m:ResponseCode>
        <m:Folders>
        <t:Folder><t:FolderId Id="AAAbAEJhbGFrcmlzaG5hbl9SQHN5bWFudGVjLmNvbQAuAAAAAACALDzcpfeRQ7ZlsoKB0iVmAQAjK9sGaxZsQpt2dmaMGjhaAADek+aFAAA=" ChangeKey="AQAAABYAAAAjK9sGaxZsQpt2dmaMGjhaAADeyyJ9"/>
        </t:Folder>
        </m:Folders>
    </m:CreateFolderResponseMessage>
    </m:ResponseMessages>
</m:CreateFolderResponse>
</s:Body>
</s:Envelope>

Move Item Request:

<?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:soap="http://schemas.xmlsoap.org/soap/envelope/"        
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> 
<soap:Header> <RequestServerVersion Version="Exchange2013" /> </soap:Header>  
<soap:Body>    
<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">     
    <ToFolderId>
        <t:FolderId Id="AAAbAEJhbGFrcmlzaG5hbl9SQHN5bWFudGVjLmNvbQAuAAAAAACALDzcpfeRQ7ZlsoKB0iVmAQAjK9sGaxZsQpt2dmaMGjhaAADek+aFAAA=" ChangeKey="AQAAABYAAAAjK9sGaxZsQpt2dmaMGjhaAADeyyJ9"/> 
    </ToFolderId>    
    <ItemIds>
        <t:ItemId Id="AAMkAGJiNjY2ZTk1LTZkMDEtNGQyYy05M2M2LWMyZmQwMzY1M2JhMQBGAAAAAACALDzcpfeRQ7ZlsoKB0iVmBwArZr3QPuquTIplat84SmYEAEq/mAl5AAAjK9sGaxZsQpt2dmaMGjhaAADdyMHzAAA="/>
    </ItemIds>
</MoveItem>
</soap:Body>
</soap:Envelope>

Move Item 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="1" MajorBuildNumber="1075" MinorBuildNumber="21" 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:MoveItemResponse 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:MoveItemResponseMessage ResponseClass="Error">
        <m:MessageText>The EWS Id is in EwsLegacyId format which is not supported by the Exchange version specified by your request. Please use the ConvertId method to convert the Id from EwsId to EwsLegacyId format.
        </m:MessageText>        
        <m:ResponseCode>ErrorInvalidIdMalformed</m:ResponseCode>
        <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
        <m:Items/>
    </m:MoveItemResponseMessage>
</m:ResponseMessages>
</m:MoveItemResponse>
</s:Body>
</s:Envelope>
1
What exchange version you are working against (exchange 2013)? When you sent "CreateFolder" EWS request, did you use the same "RequestServerVersion"?Slava Ivanov

1 Answers

2
votes

More likely your requests to "CreateFolder" and request "MoveItem" have different "RequestServerVersion". Read more on EWS schema versions in Exchange. EWS Id format has been changed I believe in "Exchange2007_SP1" version. This make me think you have used the example for "CreateFolder" request which include "RequestServerVersion" set to "Exchange2007" and it will return legacy folder Id.

EDIT:

I didn't try to reproduce your requests/response sequence, instead I used documented ways to send the following requests:

Request to create the folder looks like ...

<?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:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
    <t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />
</soap:Header>
<soap:Body>
    <CreateFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
        <ParentFolderId>
            <t:DistinguishedFolderId Id="msgfolderroot"/>
        </ParentFolderId>
        <Folders>
            <t:Folder>
                <t:DisplayName>Test Folder1</t:DisplayName>
            </t:Folder>
        </Folders>
    </CreateFolder>
</soap:Body>
</soap:Envelope>

And response is ...

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="1084" MinorBuildNumber="21" Version="V2017_04_14" 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:CreateFolderResponse 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:CreateFolderResponseMessage ResponseClass="Success">
                <m:ResponseCode>NoError</m:ResponseCode>
                <m:Folders>
                    <t:Folder>
                        <t:FolderId Id="AQMkADg0ZDZhNWFiLWE0Y2EtNDc4My05MGU1LTY5ZWNiOTQ5MmY5YwAuAAADEgGHnGK1T06Yq8xwQCjiHwEAkUJPW0th2EGwjXYeK6AWSQABv62c1AAAAA==" ChangeKey="AQAAABYAAACRQk9bS2HYQbCNdh4roBZJAAG/8ffU"/>
                    </t:Folder>
                </m:Folders>
            </m:CreateFolderResponseMessage>
        </m:ResponseMessages>
    </m:CreateFolderResponse>
</s:Body>
</s:Envelope>

The folder created successfully. As per documentation to perform MoveItem request I need the item's change key. I performed GetItem request and got the following 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="1" MajorBuildNumber="1084" MinorBuildNumber="21" Version="V2017_04_14" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:GetItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <m:ResponseMessages>
            <m:GetItemResponseMessage ResponseClass="Success">
                <m:ResponseCode>NoError</m:ResponseCode>
                <m:Items>
                    <t:Message>
                        <t:ItemId Id="AQMkADg0ZDZhNWFiLWE0Y2EtNDc4My05MGU1LTY5ZWNiOTQ5MmY5YwBGAAADEgGHnGK1T06Yq8xwQCjiHwcAkUJPW0th2EGwjXYeK6AWSQAAAgEMAAAAkUJPW0th2EGwjXYeK6AWSQABv62YlAAAAA==" ChangeKey="CQAAABYAAACRQk9bS2HYQbCNdh4roBZJAAG/8awE"/>
                    </t:Message>
                </m:Items>
            </m:GetItemResponseMessage>
        </m:ResponseMessages>
    </m:GetItemResponse>
</s:Body>
</s:Envelope>

And finally I need to move the item. The following is my request to move the item ....

<?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:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
    <t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />
</soap:Header>
<soap:Body>
    <MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <ToFolderId>
            <t:FolderId  Id="AQMkADg0ZDZhNWFiLWE0Y2EtNDc4My05MGU1LTY5ZWNiOTQ5MmY5YwAuAAADEgGHnGK1T06Yq8xwQCjiHwEAkUJPW0th2EGwjXYeK6AWSQABv62c1AAAAA=="/>
        </ToFolderId>
        <ItemIds>
            <t:ItemId Id="AQMkADg0ZDZhNWFiLWE0Y2EtNDc4My05MGU1LTY5ZWNiOTQ5MmY5YwBGAAADEgGHnGK1T06Yq8xwQCjiHwcAkUJPW0th2EGwjXYeK6AWSQAAAgEMAAAAkUJPW0th2EGwjXYeK6AWSQABv62YlAAAAA==" ChangeKey="CQAAABYAAACRQk9bS2HYQbCNdh4roBZJAAG/8awE"/>
        </ItemIds>
    </MoveItem>
</soap:Body>
</soap:Envelope>

It is succeeded and item has been moved to my new folder.

The following are suggestions for you to proceed with your debugging ...

  • Look at the request how you get the itemId. The issue may be there. You need to specify the same "RequestServerVersion" to get the ChangeKey.

  • I suggest you to have common function for all SOAP request you do to wrap each request body. In this case you will not get in trouble with legacy data. Something like this, very simple wrapper ...

        /**
         * Wrap an Exchange Web Services request in a SOAP envelope.
         * @private
         * @param {string} payload request XML.
         * @return {string} Ready to send SOAP EWS request.
         */
        function _wrapSoapEnvelope(payload) {
            var result = '<?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:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +
                'xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" ' +
                'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
            '<soap:Header>' +
            '<t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
            '</soap:Header>' +
            '<soap:Body>' + payload + '</soap:Body>' +
            '</soap:Envelope>';
            return result;
        };
    

In this case your requests will be very simple and unified (the following 3 requests I have used for your case) ...

        this.createFolderRequest = function (folderName) {
            var result = '<CreateFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' +
            '<ParentFolderId>' +
            '<t:DistinguishedFolderId Id="msgfolderroot"/>' +
            '</ParentFolderId>' +
            '<Folders>' +
            '<t:Folder>' +
            '<t:DisplayName>' + folderName + '</t:DisplayName>' +
            '</t:Folder>' +
            '</Folders>' +
            '</CreateFolder>';
            return _wrapSoapEnvelope(result);
        };

        this.moveItemRequest = function (folderId, itemId, changeKey) {
            var result = '<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
            '<ToFolderId>' +
            '<t:FolderId  Id="' + folderId + '"/>' +
            '</ToFolderId>' +
            '<ItemIds>' +
            '<t:ItemId Id="' + itemId + '" ChangeKey="' + changeKey + '"/>' +
            '</ItemIds>' +
            '</MoveItem>';
            return _wrapSoapEnvelope(result);
        };

        this.getChangeKeyRequest = function (itemId) {
            var result = '<GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' +
            '<ItemShape>' +
            '<t:BaseShape>IdOnly</t:BaseShape>' +
            '</ItemShape>' +
            '<ItemIds><t:ItemId Id="' + itemId + '"/></ItemIds>' +
            '</GetItem>';
            return _wrapSoapEnvelope(result);
        };
  • I suggest you check your requests as they are look different and follow Microsoft original documentation, instead of examples taken from other sources.

And this is it. The purpose of SO is QandA, not remote debugging, so you are on your own with your code issues. Please take a time to debug, clean up your code as well as read a bit more on documentation provided and you'll make it work.