Share via

Office.js attachmentIDs are different between API and EWS

Vladimir-3178 0 Reputation points
2024-10-15T08:41:02.7266667+00:00

Hi!

I cannot use the Office.js API for some attachments (doe to this bug https://github.com/OfficeDev/office-js/issues/2291), which prompted me to fetch the attachmentAPI via the GetItem-SOAP-Request from EWS. I cannot use the ID directly, instead, I do the following:

  • Get the current mails id via Office.context.mailbox.item.itemId.
  • Do a ConvertID request to convert the LegacyEwsID to an EwsID (https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/convertid-operation), otherwise I got an error in the next step that told me I was using a EwsLegacyID while EWS would expect an EwsId
  • Do a GetItem-SOAP-Request, which gives me the attachmentIDs. This works as expected.
  • At first, I tried to use this one directly in a GetAttachment-SOAP-Request, but this is not possible, I got an error telling me that I am sending a EwsLegacyID while the EWS-Server was expecting an EwsID, so I converted it again using the resuest below.
  • But I cannot use GetAttachment, here, it fails.

What is more, I noticed that the IDs returned that way and via the official Office.js API are slightly different (I got these examples from an unsigned email, since the Office.js API does not work for signed ones.):

Here is the ID from above (shorter):

AAMkADc0Nzc1ZWIxLTk4MWQtNDJmOS1iMDc1LWVjMTY2MGQyMDIzNgBGAAAAAABgkD8nKvYhQbvnlb0MKITQBwDD0csIVuZJQLwTH4IEpkvNAAAAAAEMAADD0csIVuZJQLwTH4IEpkvNAADweZP6AAA=

I get this ID via the following ConvertID-SOAP-Request:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
 <soap:Header>
  <t:RequestServerVersion Version="Exchange2013_SP1"/>
 </soap:Header>
 <soap:Body>
  <ConvertId xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
             xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
             DestinationFormat="EwsId">
  <SourceIds>
   <t:AlternateId Format="EwsLegacyId" Id="${id}"
                  Mailbox="${mailbox.userProfile.emailAddress}"/>
   </SourceIds>
  </ConvertId>
 </soap:Body>
</soap:Envelope>

Fetched via OfficeAPI (longer, Office.context.mailbox.item.attachments):

AAMkADc0Nzc1ZWIxLTk4MWQtNDJmOS1iMDc1LWVjMTY2MGQyMDIzNgBGAAAAAABgkD8nKvYhQbvnlb0MKITQBwDD0csIVuZJQLwTH4IEpkvNAAAAAAEMAADD0csIVuZJQLwTH4IEpkvNAADweZP6AAABEgAQAD9Kq9yepYBBmUkyeFtZsHk=

(this one I can send correctly to our backend and retrieve the attachment, but Office.js offers no possibility to do this for signed emails)

Can anyone point out to me the difference between the two formats? How can I get the correct attachmentID for signed attachments? I guess that I have messed up the ConvertID-Request somehow?

Thanks

Microsoft 365 and Office | Development | Other
Outlook | Windows | Classic Outlook for Windows | For business
0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.