Wen Hsiao
Wen Hsiao

Reputation: 11

Microsoft EWS api SyncFolderItems (mail) response ErrorInvalidSyncStateData but SyncState is correct

I used Microsoft EWS api SyncFolderItems to get mail changes, but got ErrorInvalidSyncStateData after several successful api calls.

The given SyncState request parameter is correct because it is the reponse from the last successful call.

The error response looks the same to the document shows

<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Header>
    <t:ServerVersionInfo MajorVersion="8" MinorVersion="0" 
                         MajorBuildNumber="628" MinorBuildNumber="0" 
                         xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" />
  </soap:Header>
  <soap:Body>
    <SyncFolderItemsResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
                             xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" 
                             xmlns="https://schemas.microsoft.com/exchange/services/2006/messages">
      <m:ResponseMessages>
        <m:SyncFolderItemsResponseMessage ResponseClass="Error">
          <m:MessageText>Synchronization state data is corrupt or otherwise invalid.</m:MessageText>
          <m:ResponseCode>ErrorInvalidSyncStateData</m:ResponseCode>
          <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
          <m:SyncState />
          <m:IncludesLastItemInRange>true</m:IncludesLastItemInRange>
        </m:SyncFolderItemsResponseMessage>
      </m:ResponseMessages>
    </SyncFolderItemsResponse>
  </soap:Body>
</soap:Envelope>

I use the above api to synchronize mails to my local storage. If I got ErrorInvalidSyncStateData, all I can do is delete all mails in my storage, and then re-synchronize mails (starting from empty SyncState).

I'm wondering if there is a better way to handle the error if someone has the experience using SyncFolderItems api.

Thank you.

Upvotes: -1

Views: 287

Answers (1)

Abhishek More
Abhishek More

Reputation: 1

There are few methods to avoid the above error. If you follow them you won't get the error.

  1. Ensuring that the sync state value you are sending matches the sync state value returned during a previous synchronization.
  2. Ensuring that you are not sending the sync state for the folder hierarchy when you attempt to sync items, and vice versa.
  3. Ensuring that you are sending the sync state for the correct root folder.
  4. Ensuring that the same root folder is specified in each request.
  5. Ensuring that the previous request did not specify a root folder of null, while the current request includes a root folder of root. Null and root are not treated the same. [Microsoft Documentation]: https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/handling-synchronization-related-errors-in-ews-in-exchange

Upvotes: 0

Related Questions