Search code examples
c#microsoft-graph-apioutlook-web-app

getAttachmentsAsync() return different IDs when it is call is JS and in C#


I am working on an outlook web add-in that gets attachments. But I found out that's API returns different ID for JS and in backend(C#)

In JS when I call Office.context.mailbox.item.getAttachmentsAsync() it is return this ID: AAMkADhlZGM3ZDRiLTc3ODEtNGRhZi05NDNhLWFiMWNkOTc1YWNkZQBGAAAAAAAvp5uuw9HTToIFsfv180ZsBwCYtBG78gMyRLPMDVxMNy4UAAAAAAEPAACYtBG78gMyRLPMDVxMNy4UAAHoiefYAAABEgAQAEK4dcJBHC5Hso8DtB+2NaQ=

In C#

var graph = new GraphServiceClient(url, authToken);
var request = graph.Me.Messages[itemId].Attachments.Request();
var attachments = await request.GetAsync();

this code return this ID AAMkADhlZGM3ZDRiLTc3ODEtNGRhZi05NDNhLWFiMWNkOTc1YWNkZQBGAAAAAAAvp5uuw9HTToIFsfv180ZsBwCYtBG78gMyRLPMDVxMNy4UAAAAAAEPAACYtBG78gMyRLPMDVxMNy4UAAHoiefYAAABEgAQAEK4dcJBHC5Hso8DtB_2NaQ=

Is there a way to avoid this?


Solution

  • Use Office.context.mailbox.convertToRestId to convert an item ID formatted for EWS into REST format.

    Get Item ID