Search code examples
exchangewebservicesmicrosoft-graph-apioutlook-restapi

Item id's and attachment id's that change


I've been struggling for months now with a random error in the ms graph api. Finally I found some sence in the whole mess, but I think there's an error in the graph api.

I've developed a multitenant outlook-addin (JS), that my clients use to store their emails and/or the attachments into a storage. I use the Office.context.mailbox.item object to fetch both the ItemId of the message and the Id's of the attachments. I send those id's off to a sevrer to do the heavy liftning of retriving the email and/or attachments, using EWS. Because the client has a choice of selecting which attachments to save, I need to send the selected attachment Id's to the server, where I retrieve the email and the attachments. However when I try to match the attachment Id's with the selected from the Outlook app they're different, and I can't find the correct attachments. This happens with random messages, with random tenants.

From what I can see from the id's for the email and the attachments, it looks like the attachment id is prefixed with the email id. Sometimes they don't match. Example:

The user select an email in the Outlook desktop client (Mac or Windows) and get this id for the email:

AAMkADYxNWNjMTRiLWFjYTYtNDM1OS04MTNjLThiNzM1ZWM0ZDFmZgBGAAAAAADbXpqFYshcSYLgLaL8DcdZBwDVFKe56AEMQo4qySw0u6tyAAAfj8mWAADVFKe56AEMQo4qySw0u6tyAABBmpnFAAA=

The attachment has this id (which DOESN'T match the email id):

AAMkADYxNWNjMTRiLWFjYTYtNDM1OS04MTNjLThiNzM1ZWM0ZDFmZgBGAAAAAADbXpqFYshcSYLgLaL8DcdZBwDVFKe56AEMQo4qySw0u6tyAAAAAAEJAADVFKe56AEMQo4qySw0u6tyAABBmmK4AAABEgAQAOBOPI4JZ71CuMzlk7nqfZw=

but when I query the EWS using the email id (I'm aware of the REST/EWS id differences), I get this id for the attachment (which DO match the email id):

AAMkADYxNWNjMTRiLWFjYTYtNDM1OS04MTNjLThiNzM1ZWM0ZDFmZgBGAAAAAADbXpqFYshcSYLgLaL8DcdZBwDVFKe56AEMQo4qySw0u6tyAAAfj8mWAADVFKe56AEMQo4qySw0u6tyAABBmpnFAAABEgAQAOBOPI4JZ71CuMzlk7nqfZw=

The funny thing is, that it works from OWA - this attahcment id is correct. This specific email has been moved, and I know that when moving files, the id changes, but shouldn't the attachment id then follow along? In EWS the id seems to have changed but not in Outlook


Solution

  • I used my Id-Whispering skills to look at your ids.

    The first one is the id of the item itself, not an attachment on the item. The actual PR_ENTRYID for this id is AAAAANtemoViyFxJguAtovwNx1kHANUUp7noAQxCjirJLDS7q3IAAB+PyZYAANUUp7noAQxCjirJLDS7q3IAAEGamcUAAA==

    The second one is an attachment, but the parent item is different. The PR_ENTRYID for this id is AAAAANtemoViyFxJguAtovwNx1kHANUUp7noAQxCjirJLDS7q3IAAAAAAQkAANUUp7noAQxCjirJLDS7q3IAAEGaYrgAAA==

    Attachment id part: EADgTjyOCWe9QrjM5ZO56n2c

    The third one is also an attachment, same "attachment id" part of the id, but in this case, it refers to the item in the original location. As you can see, the PR_ENTRYID matches: AAAAANtemoViyFxJguAtovwNx1kHANUUp7noAQxCjirJLDS7q3IAAB+PyZYAANUUp7noAQxCjirJLDS7q3IAAEGamcUAAA==

    Attachment id part: EADgTjyOCWe9QrjM5ZO56n2c

    So what happened here? What it looks like is that in the second case, the item was in a different folder. PR_ENTRYID made up of the FID (folder id) and the MID (message id). As a result, if an item moves from one folder to another, then the id changes. You move it back, it reverts back to its old id. Weird, I know.

    That's a good reason for Microsoft to come up with an immutable id :)