microsoft-graph-apioutlook-restapimicrosoft-contracts

Outlook contacts change their ID when you move them to another folder


I have a problem with the Microsoft Graph Rest API. I have written a progam that should read the contacts from Outlook and later match them again and again. For this I use the ID from the contacts record. My program reads over all folders and gets the necessary information about all contacts. This works quite well so far.

Now I surprisingly got a problem, because the ID of a contact in Outlook can change and therefore I lose my reference to my external dataset.

The following case causes me problems.

  1. I create a contact in Outlook. This contact has an ID after reading it out via the Rest API.

{'@odata.etag': 'W/"EQAAABYAAADqyc40Bfr0RZDGyWTzcCdWAADu40Xu"', 'id': 'AAMkADE4MWMwOTY4LTM2ODAtNDAyZS1iZDgwLWEyYjE3NTUxY2U4OABGAAAAAACYta-jK-baT5Lfw8NopJJYBwDqyc40Bfr0RZDGyWTzcCdWAADCW0U2AADqyc40Bfr0RZDGyWTzcCdWAADvCEp-AAA=', 'displayName': 'Max Mustermann'}

  1. I use the "move to" option for a contact to move it to another folder. After that this contact has a different ID.

{'@odata.etag': 'W/"EQAAABYAAADqyc40Bfr0RZDGyWTzcCdWAADu40YP"', 'id': 'AAMkADE4MWMwOTY4LTM2ODAtNDAyZS1iZDgwLWEyYjE3NTUxY2U4OABGAAAAAACYta-jK-baT5Lfw8NopJJYBwDqyc40Bfr0RZDGyWTzcCdWAADvCHYwAADqyc40Bfr0RZDGyWTzcCdWAADvCLTCAAA=', 'displayName': 'Max Mustermann'}

Can anyone give me a tip on how to prevent this? ... or is there a way to read the old ID's of a contact?

Maybe someone can explain me, why the ID changes at all, if I move the contact to a folder.

Any help is welcome.


Solution

  • The reason is described here:

    Outlook items (messages, events, contacts, tasks) have an interesting behavior that you've probably either never noticed or has caused you significant frustration: their IDs change. It doesn't happen often, only if the item is moved, but it can cause real problems for apps that store IDs offline for later use. Immutable identifiers enables your application to obtain an ID that does not change for the lifetime of the item.

    https://learn.microsoft.com/en-us/graph/outlook-immutable-id

    And also the solution:

    Immutable ID is an optional feature for Microsoft Graph. To opt in, your application needs to send an additional HTTP header in your API requests:

    Prefer: IdType="ImmutableId"

    This header only applies to the request it is included with. If you want to always use immutable IDs, you must include this header with every API request.

    https://learn.microsoft.com/en-us/graph/outlook-immutable-id#how-it-works