Search code examples
microsoft-graph-apiexchangewebservices

How do I convert an EWS change key to a Graph change key?


I want to convert a EWS managed API change key to the change key the Graph API returns for the same calendar event.

The EWS change key (obtained with this API) is

<t:ItemId ChangeKey="DwAAABYAAAB19EH4lfKlQYvApCHA0Dr0AABILgj3"/>

but the Graph change key (obtained with this one) is vastly different:

"changeKey": "dfRB+JXypUGLwKQhwNA69AAASC4I9w=="

The document about Graph calendar events indicates that they serve the same purpose, but it does not mention how to convert between the two nor why are the formats so different.

How do I convert between these two? I can't use any C# or powershell libraries, and I'd like to avoid sending additional APIs if possible.


Solution

  • You can do this using the translateExchangeIds API.

    POST https://graph.microsoft.com/v1.0/users/{userId}/translateExchangeIds
    
    {
      "InputIds": ["DwAAABYAAAB19EH4lfKlQYvApCHA0Dr0AABILgj3"],
      "TargetIdType": "restId",
      "SourceIdType": "ewsId"
    }
    

    The response will have this shape:

    {
        "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.convertIdResult)",
        "value": [
            {
                "sourceId": "AAMkADEzOTExYjJkLTYxZDAAb18KkFAAA=",
                "targetId": "AAMkADEzOTExoeGgGqm4QrAAb18KkFAAA="
            }
        ]
    }
    

    The potential TargetIdType and SourceIdType values are:

     <EnumType Name="exchangeIdFormat">
        <Member Name="entryId" Value="0" />
        <Member Name="ewsId" Value="1" />
        <Member Name="immutableEntryId" Value="2" />
        <Member Name="restId" Value="3" />
        <Member Name="restImmutableEntryId" Value="4" />
      </EnumType>
    

    This will be available in the next update of the client libraries.

    update

    Once you have a converted item identifier, you can request the item and select the changekey property. It would make sense to do this in batches.

    GET https://graph.microsoft.com/v1.0/users/{userId}/messages/{messageid}/?$select=changekey