BigDataFiles
BigDataFiles

Reputation: 185

MoveItem Invalid Request

I'm trying to delete an item using the EWS MoveItem XML request. I'm sending this request to the makeEwsRequestAsync function:

function getMoveItemRequest(id, changeKey) {

    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:t="https://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>' +
        '<MoveItem xmlns="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">' +
            '<ToFolderId>' +
                '<t:DistinguishedFolderId Id="deleteditems" />' +
            '</ToFolderId>' +
            '<ItemIds>' +
                '<t:ItemId Id="' + id + '" ChangeKey="' + changeKey + '" />' +
            '</ItemIds>' +
        '</MoveItem>' +
        '</soap:Body>' +
        '</soap:Envelope>';

    return result;
}

I'm getting the item id from the message like this:

Office.context.mailbox.item.itemId

I'm getting changekey like this:

var mailbox = Office.context.mailbox;
var soapToGetItemData = getItemDataRequest(mailbox.item.itemId);

    Office.context.mailbox.makeEwsRequestAsync(soapToGetItemData, function(result) {
        var response = $.parseXML(result.value);
        var responseString = result.value;

        // TODO: May want to reconsider the logic for getting the ChangeKey
        var indexOfChangeKey = responseString.indexOf("ChangeKey=\"");
        var substringAfterChangeKey = responseString.substring(indexOfChangeKey + 11);
        var indexOfQuotes = substringAfterChangeKey.indexOf("\"");
        var changeKey = substringAfterChangeKey.substring(0, indexOfQuotes);

Here is the getItemDataRequest function:

function getItemDataRequest(itemId) {
    var soapToGetItemData = '<?xml version="1.0" encoding="utf-8"?>' +
        '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
        '               xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"' +
        '               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" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
        '  </soap:Header>' +
        '  <soap:Body>' +
        '    <GetItem' +
        '                xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"' +
        '                xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
        '      <ItemShape>' +
        '        <t:BaseShape>IdOnly</t:BaseShape>' +
        '        <t:AdditionalProperties>' +
        '            <t:FieldURI FieldURI="item:Attachments" /> ' +
        '        </t:AdditionalProperties> ' +
        '      </ItemShape>' +
        '      <ItemIds>' +
        '        <t:ItemId Id="' + itemId + '"/>' +
        '      </ItemIds>' +
        '    </GetItem>' +
        '  </soap:Body>' +
        '</soap:Envelope>';
    return soapToGetItemData;
}

Yet, I'm getting an invalid response from this (the XML that is returned has "<faultstring xml:lang="en-US">The request is invalid." in it.)

Any ideas what's going on?

Thanks!

Upvotes: 0

Views: 116

Answers (1)

BigDataFiles
BigDataFiles

Reputation: 185

Needed to use http instead of https in the request.

function getMoveItemRequest(id, changeKey) {
    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: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:DistinguishedFolderId Id="deleteditems"/> ' +
                '</ToFolderId> ' +
                '<ItemIds> ' +
                    '<t:ItemId Id="' + id + '" ChangeKey="' + changeKey + '"/> ' +
                '</ItemIds> ' +
            '</MoveItem> ' +
        '</soap:Body> ' +
        '</soap:Envelope> ';

    return result;
}

Upvotes: 1

Related Questions