3

Whats the reason that make a calendar change it's id when using microsoft graph ???

This happened today for one of our clients who's been using his main Calendar for over 2 years, and suddenly today, the id is changed and we are unable to add any event since we have the 'old' id

Endpoint being called:

/me/calendars/AAMkAGFmMzAxNmRkLTg4YTEtNDNhZS1iYjExLWE1OThlYThlNTRmOQBGAAAAAACxNL6zUoo_Qr9AY8vFoIfmBwBstbpyrelbSJu1keAu6bMkAAAAAAEGAABstbpyrelbSJu1keAu6bMkAAAAAFB8AAA=/events

Error returned:

{
  "error": {
    "code": "ErrorItemNotFound",
    "message": "The specified object was not found in the store."
  }
}

Headers:

{
  "Cache-Control": [
    "private"
  ],
  "Content-Type": [
    "application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8"
  ],
  "request-id": [
    "63353567-4ebd-4b25-903b-d66717797882"
  ],
  "client-request-id": [
    "63353567-4ebd-4b25-903b-d66717797882"
  ],
  "x-ms-ags-diagnostic": [
    "{\"ServerInfo\":{\"DataCenter\":\"North Europe\",\"Slice\":\"SliceC\",\"Ring\":\"4\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"AGSFE_IN_6\"}}"
  ],
  "Strict-Transport-Security": [
    "max-age=31536000"
  ],
  "Date": [
    "Thu, 04 Feb 2021 10:40:39 GMT"
  ],
  "Content-Length": [
    "99"
  ]
}

New calendar id: AAMkAGFmMzAxNmRkLTg4YTEtNDNhZS1iYjExLWE1OThlYThlNTRmOQBGAAAAAACxNL6zUoo_Qr9AY8vFoIfmBwBstbpyrelbSJu1keAu6bMkAAAAAAEGAABstbpyrelbSJu1keAu6bMkAAF8qLRIAAA=

Edit: (Happened for another client) It happened again today with another client (another tenant-id), here are details:

Old calendar id:

AAMkAGI2Y2NkYzVmLTc3ZjUtNDQyNi1iNjIzLTljNjkyMDk5YjEyYwBGAAAAAADQqVqZh-ZpQJl-EcoJBivzBwCE3CCn1SYkSLnEBiNMaH3ZAAAAAAEGAACE3CCn1SYkSLnEBiNMaH3ZAAAAAB08AAA=
{
   "Cache-Control":[
      "private"
   ],
   "Content-Type":[
      "application\/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8"
   ],
   "request-id":[
      "2f9ddb93-3594-4d86-97f9-d7dbe960a2bb"
   ],
   "client-request-id":[
      "2f9ddb93-3594-4d86-97f9-d7dbe960a2bb"
   ],
   "x-ms-ags-diagnostic":[
      "{\"ServerInfo\":{\"DataCenter\":\"North Europe\",\"Slice\":\"SliceC\",\"Ring\":\"4\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"AGSFE_IN_71\"}}"
   ],
   "Strict-Transport-Security":[
      "max-age=31536000"
   ],
   "Date":[
      "Mon, 08 Feb 2021 11:08:53 GMT"
   ],
   "Content-Length":[
      "99"
   ]
}

New calendar id:

AAMkAGI2Y2NkYzVmLTc3ZjUtNDQyNi1iNjIzLTljNjkyMDk5YjEyYwBGAAAAAADQqVqZh-ZpQJl-EcoJBivzBwCE3CCn1SYkSLnEBiNMaH3ZAAAAAAEGAACE3CCn1SYkSLnEBiNMaH3ZAAGPkTa6AAA=
Herz3h
  • 614
  • 5
  • 20
  • https://stackoverflow.com/a/58399493/2250152 – user2250152 Feb 04 '21 at 13:37
  • Interesting thread/info... you may want to check with Microsoft support and see where they stand on this. – Dev Feb 04 '21 at 16:22
  • Not sure why it happens but alternatively you can use `/me/calendars` endpoint and get the needed calendarid and then try to create events by `/me/calendars/claendarid/events`. – Shiva Keshav Varma Feb 05 '21 at 03:20
  • @ShivaKeshavVarma Unfortunately, using the new calendar id is not really a good solution. Since we'd loose every application specific info that we store (say an event stored in our app has a relation with other tables. If I simply add the new calendar, I think the iCalUID for each event will also be different, and therefore we lose every relation that event have in our app, we end up with just plain events like in Outlook) – Herz3h Feb 05 '21 at 07:43
  • 1
    @Dev they advise to post on stackoverflow for support :/ – Herz3h Feb 05 '21 at 07:43
  • Aah ok. In such scenario, i am throwing a solution to give a try: When you create a new events, create your custom MAPI property stamp it in these items, it will exist and you can make use of them without depending on other ways. Or you can come with combo of couple of standard MAPI properties which exist. – Dev Feb 05 '21 at 08:16
  • @Dev I appreciate the suggestion to help, unfortunately my issue is with events that existed in old calendar id. Those events will lose all application specific informations in our app since that calendar no longer exists. I'm just hoping for a bugfix from microsoft to revert calendar id here. – Herz3h Feb 05 '21 at 13:36
  • Interesting.. Just adding my views here. Based on my understanding unless the mailbox is not recreated the IDs wont change. I see the same what DavidSterling echo in the above thread too; i think Jeremy is echo-ing the same too. Do you have any known history for the given mailbox? or move the items from one mailbox to another? – Dev Feb 05 '21 at 15:51
  • @Dev I don't have history for the given mailbox, this bug happened for another client (see my other answer). I ended up importing the new calendar into the application, luckily the events from the previous calendar have the same IcalUId as the "new" calendar. That will do for now, hopefully a microsoft engineer comes by and takes details up to the responsible team. – Herz3h Feb 09 '21 at 07:57
  • 1
    Without knowing the history of the given mailbox is tough to comment - the issue might be happening due to mailbox history/migrations/indexing or mailbox recreation etc. Here Graph API's are just messengers which are returning the back to you. If there is an issue in a source then it will share only the data. As i updated earlier you may want to try the approach or using iCalUID to see if it fits your scenario. But yes it may apply only to the new items, for older items you may need to stamp it and make use of them too. – Dev Feb 11 '21 at 09:39
  • 1
    Jan 2023 and this bug still happens @MSFT we have to remove and fetch the new calendar id to add it.. – Herz3h Jan 27 '23 at 07:02
  • @Herz3h I'm currently in contact with Graph support and they're utterly useless... Have you found a reliable workaround to refetch calendar ids? Only thing I currently can think of is comparing calendar names to update a calendar id when it's not found anymore. Boy... it's so frustrating... – Daniel Mar 21 '23 at 08:33
  • @Daniel Unfortunately no solution, problem still occurs, we just remove and add the calendar with the new id....... – Herz3h Jul 19 '23 at 08:59

2 Answers2

4

Here's a piece of the puzzle... Those look Base64 encoded. If you Base 64 decode the old and the new IDs, you'll find the same GUIDs are embedded inside it.

(Use https://www.base64decode.org/)

Old decoded: $af3016dd-88a1-43ae-bb11-a598ea8e54f9F4R?B@cŠlr[H.$lr[H.$P|
New decoded: $af3016dd-88a1-43ae-bb11-a598ea8e54f9F4R?B@cŠlr[H.$lr[H.$|H
(guid: af3016dd-88a1-43ae-bb11-a598ea8e54f9)
- 
2nd example provided 
Old decoded: $b6ccdc5f-77f5-4426-b623-9c692099b12cFЩZi@~    + &$H#Lh} &$H#Lh}<
New decoded: $b6ccdc5f-77f5-4426-b623-9c692099b12cFЩZi@~    + &$H#Lh} &$H#Lh}6
(guid: b6ccdc5f-77f5-4426-b623-9c692099b12c)

If it is not possible to use the embedded GUID via a query in the graph request, then maybe call https://graph.microsoft.com/v1.0/me/calendars, decode all the calendars, find the ID with the matching embedded GUID, and use that one? It would add an extra call, but you might be able to do it in exception handling, as no state is required. This may help with your existing application.

I can't guarantee this would work as I don't have data over time to test this theory with... but you do :)

To avoid this issue with ID changes going forward, look into storing immutable IDs wherever possible. You cannot store them for containers (calendars, mailboxes, etc), but perhaps moving forward you can store them for the events that your application creates, so you can work backwards from there.

Container types (mailFolder, calendar, etc.) do not support immutable ID, but their regular IDs were already constant.

This line from their documentation is notable, as your experience does not match what their documentation states. This opens scope for you to complain to MS, or at least meaningfully blame their wrong documentation.

Also, I'd be asking IT in both orgs if they changed anything related to AAD Sync or Exchange? I have got a wild theory it's related to that. There was an email that went out recently asking people to update AAD sync, and this pattern just feels familiar to some sort of auth provider change.


Update: as to solving this problem directly; A potential way could be to have an exception handling piece of logic that only runs when the URL 404s. It would behave as follows:

  1. Using regex, Get the base64 decodable segment of the URL and decode it.
  2. Using regex, Find all possible matches for a GUID. (regex?)
  3. Use the Graph API to find the calendar identified by any found GUID.
  4. Use new URL, and see if that works.
  5. If it does, update your record to the new URL.
alirobe
  • 846
  • 6
  • 11
  • Didn't know the calendar's ID contains a Based64-encoded GUID. Does this also mean calendar IDs are unique across the entire Microsoft tenant, not just for a particular user/mailbox? I'm running into a similar requirement where I really need to identity unique Microsoft calendars in my multi-user, multi-tenant app. I'm not sure if using the Id is enough. – thankyoussd Feb 15 '21 at 06:03
  • 1
    Well, I dunno. Microsoft does damn weird things with GUIDs. Definitely try to find a basis for what you're doing in the documentation. – alirobe Feb 15 '21 at 06:16
  • How did you solve this? I encountered this exact same issue and it's driving me nuts... – Daniel Mar 07 '23 at 10:45
  • A way to solve this could be to have an exception handling piece of logic that only runs when the URL 404s. It would use the Graph API to find the calendar using the GUID that is embedded in the URL, use the new URL, and then if/when that works, update your record to the new URL. I've put this in the bottom of my answer. – alirobe Mar 29 '23 at 22:07
-1

The problem is not that the calendar id changed. It seems like you just have to deal with it, and you have a good way to find the new Id, as stated in the above comment.

The problem is that you use the ID Microsoft is generating, in your app, and now they don’t match. It’s perfectly possible to add extra data to an event (or a user/group). See this page for more info. That way you can just add your external ID to the event while creating and then you can always find back the event.

Stephan
  • 2,356
  • 16
  • 38
  • 1
    Well yeah can always do that on most existing API, but the point is the public ID of the calendar is supposed to fill that role of being unique and immutable. Of course there are always workarounds, but it involves more work on something thats not supposed to happen in the first place. I mean why have the API return ids if they randomly changes.. – Herz3h Feb 11 '21 at 07:42
  • If they stayed the same for several years, they seem pretty static to me. If you have a webapplication that uses int as a key for items. And then you decide that it has to be an guid. To migrate you have to change all the existing id's, but you can still call the id unique and immutable. – Stephan Feb 11 '21 at 13:23