I'm a junior developer trying to figure out the Outlook365 REST API.
I'm using the office365 rest api to sync my events from my calendar. On my first request, I get all the events from a time range. This returns a deltaToken. After that I add more events to my calendar and make another call using the last deltaToken returned from my calls. This request returns all the events (including the new ones) and 2 deltaTokens (the first is the one I've sent, and the second is a new one). I only want to get the new events, not all of them. If I'm making the request using the deltaToken from my previous request, does that not mean that I've already synced all my previous events and shouldn't the next calls get only the new / modified events?
Below is a response. Is it ok to have 2 deltaTokens in my response?
{"@odata.context":"https://outlook.office.com/api/beta/$metadata#Me/CalendarView, "value":[list of events], "@odata.deltaLink":"https://outlook.office.com/api/beta/Me/CalendarView/?startDateTime=2017-07-25T00%3a00%3a00Z&endDateTime=2017-09-01T00%3a00%3a00Z&deltatoken=GGXXX&%24deltatoken=GWXXX" }
It sounds like you are not finalizing your first sync. The way sync works in the API is a little counter-intuitive. It isn't as simple as checking for a deltaToken to see if you're done.
The reason is that the first request with
Prefer: odata.track-changes
always returns a deltaToken, even if there are more results. The docs give more detail here, but the general sequence is:Prefer: odata.track-changes
.Preference-Applied: odata.track-changes
header is present in response. If so, get thedeltaLink
and do a GET on that.nextLink
in response, do a GET on that and repeat. If you get adeltaLink
, the sync is done. Store the value until your next sync.