0
votes

I am using the Microsoft Outlook REST API to synchronize messages in a folder using skipTokens with the Prefer: odata.track-changes header.

After 62 successful rounds of results, I get an error 500 ErrorInternalServerError with the message Unable to cast object of type 'LegacyPagingToken' to type 'Microsoft.Exchange.Services.OData.Model.SkipToken'

I have tried:

  • Retrying the same query (https://outlook.office.com/api/v2.0/me/MailFolders/Inbox/messages/?%24skipToken=1BWUA9eXs5dN89tPsr_FOvtzINQAA0Cwk5o), which results in the same error
  • Restarting the sync, which results in the same error at the same point
  • Adding a new message to the Inbox and restarting the sync, which results in the same error at the same point
  • Moving the messages from that part of the sync to another folder (in case the messages themselves were causing the problem), which results in the same error at the same point

Has anybody run into this error or have suggestions on what might cause it or workarounds?

1

1 Answers

1
votes

It looks like the issue was on my end while parsing the skipToken from the @odata.nextLink response. The token in the original question is invalid - the actual skipToken passed back from the API had -AAAA on the end. After 63 queries, in which the skipToken increments, the Base64 encoded form started using characters the regexp I was using didn't find. Switching from a \w regexp to a proper URL parser solved the problem.