none
[Exchange-Online] [EWS-XML] SyncState in EWS SyncFolderItems request doesn't work properly for the "To-Do Search" folder? RRS feed

  • Question

  • Steps:

    1. The "To-Do" view is clean. I create a new task. The task appears in the "To-Do" view in the Outlook app.

    2. I execute the following EWS request against the https://outlook.office365.com/EWS/Exchange.asmx endpoint:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
      <SOAP-ENV:Header>
        <ns2:RequestServerVersion xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns3="http://schemas.microsoft.com/exchange/services/2006/messages" Version="Exchange2007_SP1"/>
      </SOAP-ENV:Header>
      <SOAP-ENV:Body>
        <ns2:SyncFolderItems xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/messages">
          <ns2:ItemShape>
            <BaseShape>IdOnly</BaseShape>
            <AdditionalProperties>
              <FieldURI FieldURI="item:DateTimeReceived"/>
              <FieldURI FieldURI="item:Subject"/>
            </AdditionalProperties>
          </ns2:ItemShape>
          <ns2:SyncFolderId>
            <DistinguishedFolderId Id="todosearch"/>
          </ns2:SyncFolderId>
          <ns2:MaxChangesReturned>500</ns2:MaxChangesReturned>
        </ns2:SyncFolderItems>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>


    The response returned by EWS is:

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
       <s:Header>
          <h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="260" MinorBuildNumber="5" Version="V2017_10_09" 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:SyncFolderItemsResponse 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:SyncFolderItemsResponseMessage ResponseClass="Success">
                   <m:ResponseCode>NoError</m:ResponseCode>
                   <m:SyncState>H4sIAAAAAAAEAGNgYGcAAotqE0tHE2NTA0ddZ3NHC10TR2djXSdnJ2ddNyMnC2cnczdLU1OD2vBgveDKvOTgksSSVOfEvMSiSgYr0nW65eekpBZ5pjBYkq43LLWoODM/j8GaaK3+QMuKS4JSk1Mzy1JTQjJzU0nwrU9icYlnXnFJYl5yqncqKb71zS9K9SxJzS32zwtOLSpLLSLByXDfhgNxUW5iUTYklrgYGISA0tDwAxkOUskgCJQyAGI9kJqDP+PWCjMyenYrv3m4kOnaP0YG/sdVvIFmKv5zK2YIH2XR28vAwLZG6zoD0Eg+BmaQFm6Gr6k6wnVGVz0YhBgYGXiBGGjdJKCMr2OAp6+jH0gRg5upWxhYORoIAGI5JH4eEEtgUYcO0J0VBBZlZGBoVVSpx5BlA4pzKExkMGJgaAAA8Vq257QCAAA=</m:SyncState>
                   <m:IncludesLastItemInRange>true</m:IncludesLastItemInRange>
                   <m:Changes>
                      <t:Create>
                         <t:Task>
                            <t:ItemId Id="AAMkAGExNGI0MTZiLTExNTEtNDQ4MS05N2Y0LTMxMTliZjRkODc2MwBGAAAAAADB+V6tEwEBSYsj7OGhAtb+BwAP43oNUTYkT514mBPFBC69AAAGrCrXAAAP43oNUTYkT514mBPFBC69AACFCCCRAAA=" ChangeKey="EwAAABYAAAAP43oNUTYkT514mBPFBC69AACFILv9"/>
                            <t:Subject>task-to-be-synced</t:Subject>
                            <t:DateTimeReceived>2017-11-23T14:23:21Z</t:DateTimeReceived>
                         </t:Task>
                      </t:Create>
                   </m:Changes>
                </m:SyncFolderItemsResponseMessage>
             </m:ResponseMessages>
          </m:SyncFolderItemsResponse>
       </s:Body>
    </s:Envelope>


    3. Then I update the task (alter the subject and the body as well). I validate that the change is propagated to the server by observing the updated task in another client (OWA, for instance).

    4. After that I execute the following request, which is almost the same as in #2 except now it provides a sync id:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
      <SOAP-ENV:Header>
        <ns2:RequestServerVersion xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns3="http://schemas.microsoft.com/exchange/services/2006/messages" Version="Exchange2007_SP1"/>
      </SOAP-ENV:Header>
      <SOAP-ENV:Body>
        <ns2:SyncFolderItems xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/messages">
          <ns2:ItemShape>
            <BaseShape>IdOnly</BaseShape>
            <AdditionalProperties>
              <FieldURI FieldURI="item:DateTimeReceived"/>
              <FieldURI FieldURI="item:Subject"/>
            </AdditionalProperties>
          </ns2:ItemShape>
          <ns2:SyncFolderId>
            <DistinguishedFolderId Id="todosearch"/>
          </ns2:SyncFolderId>
          <ns2:SyncState>H4sIAAAAAAAEAGNgYGcAAotqE0tHE2NTA0ddZ3NHC10TR2djXSdnJ2ddNyMnC2cnczdLU1OD2vBgveDKvOTgksSSVOfEvMSiSgYr0nW65eekpBZ5pjBYkq43LLWoODM/j8GaaK3+QMuKS4JSk1Mzy1JTQjJzU0nwrU9icYlnXnFJYl5yqncqKb71zS9K9SxJzS32zwtOLSpLLSLByXDfhgNxUW5iUTYklrgYGISA0tDwAxkOUskgCJQyAGI9kJqDP+PWCjMyenYrv3m4kOnaP0YG/sdVvIFmKv5zK2YIH2XR28vAwLZG6zoD0Eg+BmaQFm6Gr6k6wnVGVz0YhBgYGXiBGGjdJKCMr2OAp6+jH0gRg5upWxhYORoIAGI5JH4eEEtgUYcO0J0VBBZlZGBoVVSpx5BlA4pzKExkMGJgaAAA8Vq257QCAAA=</ns2:SyncState>
          <ns2:MaxChangesReturned>500</ns2:MaxChangesReturned>
        </ns2:SyncFolderItems>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    As a result I receive:

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
       <s:Header>
          <h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="260" MinorBuildNumber="5" Version="V2017_10_09" 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:SyncFolderItemsResponse 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:SyncFolderItemsResponseMessage ResponseClass="Success">
                   <m:ResponseCode>NoError</m:ResponseCode>
                   <m:SyncState>H4sIAAAAAAAEAGNgYGcAAotqE0tHE2NTA0ddZ3NHC10TR2djXSdnJ2ddNyMnC2cnczdLU1OD2vBgveDKvOTgksSSVOfEvMSiSgYr0nW65eekpBZ5pjBYkq43LLWoODM/j8GaaK3+QMuKS4JSk1Mzy1JTQjJzU0nwrU9icYlnXnFJYl5yqncqKb71zS9K9SxJzS32zwtOLSpLLSLByXDfhgNxUW5iUTYklrgYGISA0tDwAxkOUskgCJQyAGI9kJqDP+PWCjMyenYrv3m4kOnaP0YG/sdVvIFmKv5zK2YIH2XR28vAwLZG6zoD0Eg+BmaQFm6Gr6k6wnVGVz0YhBgYGXiBGGjdBqCMr2OAp6+jH0gRg5upWxhYORpoA2I5JH4AEEtgUYcO0J3FxsDQyqEwEUgqqtTjlEUXDwKbxQjWtZnBiIGhAQAdF6rm0gIAAA==</m:SyncState>
                   <m:IncludesLastItemInRange>true</m:IncludesLastItemInRange>
                   <m:Changes/>
                </m:SyncFolderItemsResponseMessage>
             </m:ResponseMessages>
          </m:SyncFolderItemsResponse>
       </s:Body>
    </s:Envelope>

    Basically it means I don't get the update at all!

    5. If I execute a SyncFolderItems without a sync id again (like in #2), I do get the most recent values:

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
       <s:Header>
          <h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="260" MinorBuildNumber="5" Version="V2017_10_09" 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:SyncFolderItemsResponse 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:SyncFolderItemsResponseMessage ResponseClass="Success">
                   <m:ResponseCode>NoError</m:ResponseCode>
                   <m:SyncState>H4sIAAAAAAAEAGNgYGcAAotqE0tHE2NTA0ddZ3NHC10TR2djXSdnJ2ddNyMnC2cnczdLU1OD2vBgveDKvOTgksSSVOfEvMSiSgYr0nW65eekpBZ5pjBYkq43LLWoODM/j8GaaK3+QMuKS4JSk1Mzy1JTQjJzU0nwrU9icYlnXnFJYl5yqncqKb71zS9K9SxJzS32zwtOLSpLLSLByXDfhgNxUW5iUTYklrgYGISA0tDwAxkOUskgCJQyAGI9kJqDP+PWCjMyenYrv3m4kOnaP0YG/sdVvIFmKv5zK2YIH2XR28vAwLZG6zoD0Eg+BmaQFm6GU2vMl9YbXfVgEGJgZOAFYqB1k4Ayvo4Bnr6OfiBFDG6mbmFg5WggAIjlkPh5QCyBRR06QHdWEFiUkYGhVVFlM4YsG1CcQ2EigzEDQwMAOLR+2LQCAAA=</m:SyncState>
                   <m:IncludesLastItemInRange>true</m:IncludesLastItemInRange>
                   <m:Changes>
                      <t:Create>
                         <t:Task>
                            <t:ItemId Id="AAMkAGExNGI0MTZiLTExNTEtNDQ4MS05N2Y0LTMxMTliZjRkODc2MwBGAAAAAADB+V6tEwEBSYsj7OGhAtb+BwAP43oNUTYkT514mBPFBC69AAAGrCrXAAAP43oNUTYkT514mBPFBC69AACFCCCRAAA=" ChangeKey="EwAAABYAAAAP43oNUTYkT514mBPFBC69AACFILv/"/>
                            <t:Subject>task-to-be-synced [UPDATED]</t:Subject>
                            <t:DateTimeReceived>2017-11-23T14:23:21Z</t:DateTimeReceived>
                         </t:Task>
                      </t:Create>
                   </m:Changes>
                </m:SyncFolderItemsResponseMessage>
             </m:ResponseMessages>
          </m:SyncFolderItemsResponse>
       </s:Body>
    </s:Envelope>


    Why is it so?

    If I play around with another folder (e.g. "drafts"), the same steps work fine: at #4 I get my updates!

    Thursday, November 23, 2017 2:48 PM

Answers

  • Because that folder is a Search Folder (eg not a real folder) SyncFolderItem isn't supported on these types of folder see https://msdn.microsoft.com/en-us/library/office/dn440952(v=exchg.150).aspx

    "When synchronizing search folders:

    • Use an approach similar to notification-based synchronization.

    • Use notifications to determine when data changes.

    • Because you can’t use SyncFolderItem in a search folder, use a sorted and paged EWS Managed API FindItems method, or EWS FindItem operation with the FractionalPageItemView and SortOrder element set, to determine what changed.

    • Use the EWS Managed API LoadPropertiesForItems method or the EWS GetItem operation to retrieve data."

    • Marked as answer by Shaphan Monday, November 27, 2017 11:55 PM
    Monday, November 27, 2017 10:28 AM

All replies

  • Because that folder is a Search Folder (eg not a real folder) SyncFolderItem isn't supported on these types of folder see https://msdn.microsoft.com/en-us/library/office/dn440952(v=exchg.150).aspx

    "When synchronizing search folders:

    • Use an approach similar to notification-based synchronization.

    • Use notifications to determine when data changes.

    • Because you can’t use SyncFolderItem in a search folder, use a sorted and paged EWS Managed API FindItems method, or EWS FindItem operation with the FractionalPageItemView and SortOrder element set, to determine what changed.

    • Use the EWS Managed API LoadPropertiesForItems method or the EWS GetItem operation to retrieve data."

    • Marked as answer by Shaphan Monday, November 27, 2017 11:55 PM
    Monday, November 27, 2017 10:28 AM
  • Glen, thanks a lot for your answer!

    Is there by any chance a regular folder that contains all message items flagged for follow-up (like the "To-Do Search" one)?

    Monday, November 27, 2017 11:58 PM
  • No the point of the Search folder is that it searchs all the folders eg I flag items for followup in my Inbox while user A is a mail sorter and sorts all their email in different folders in the Inbox with the followup flag set. I guess the one thing to consider when syncing this is that number of Items should never be really that high.
    Wednesday, November 29, 2017 12:55 AM