Mapping Office365 REST Calendar IDs to EWS Calenda

2019-04-03 11:40发布

Using Exchange push notifications I've been creating a service that syncs over calendar data from Office365 users. I've been using a combination of the Office365 Calendar REST API (to get and manage calendars) and the EWS API (to subscribe to calendar changes).

I noticed that just recently MS has introduced a preview API for their subscription endpoints. However, this API is still in preview mode and I'd like to avoid using it for the time being.

Once I have everything setup, the problem is I can't make a correlation between the calendar event resource (REST) and the EWS CalendarItem resource that is returned on a push notification. The ItemId for the CalendarItem and the Id for the REST event differ.

When attempting to update the events that I've saved from the REST API this proves problematic since I cannot find a good method of associating the two.

Any help is greatly appreciated!

Edit After some further digging, I've actually found that the calendars that are returned from the REST API (GET /calendars) appear to be Message items within the EWS hierarchy. So instead of this endpoint returning actual Folder IDs, it returns Item IDs that belong in some folder called "Common Views".

I'm not sure why things are designed this way, but the difference in the base64 encoded IDs seems to be very minimal. I just still can't figure out a good way to associate the two.

1条回答
来,给爷笑一个
2楼-- · 2019-04-03 12:32

So it turns out that my IDs mismatched due to subscribing to EWS push notifications via the Exchange2007 version. Exchange2007_SP1 and beyond have compatible EwsIds with each other so this includes Office365.

Replacing - characters with / and _ characters with + allows me to properly make calls to Office365 API resources.

Finally, when making a call to get calendars, the API is actually returning Message item types that live under the Common Views folder. So when attempting to use these IDs for subscriptions, the EWS API will complain that I've sent it ItemIDs and not a Folder ID.

Thankfully I've found that making a request to the REST API via GET /calendars/ews_folder_id actually works once you properly translate the ID to a URI safe type (see above conversion).

查看更多
登录 后发表回答