4

UPDATE: Many thanks to Venkat for answering this below!

The get request needs to be formatted as follows in order to retrieve the contents of a .msg attachment:

https://outlook.office365.com/api/v1.0/me/messages/{messageid}/attachments/{AttachmentId}?$expand=Microsoft.OutlookServices.ItemAttachment/Item


(Original question)

I originally asked this question in Microsoft's Office Dev Center. One of the moderators requested that I pose this question here.

I've been having a lot of success using the Office 365 Mail REST API. However, when trying to retrieve email messages that are attached to other emails (i.e., Item Attachments like .msg files), the REST API does not deliver.

When I make a GET request like this for an email that has a .msg file attached to it, I get all the attachment properties except the "Item" property, which should contain the attachment (according to the Office 365 Mail REST API resource guide here: https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#RESTAPIResourcesItemAttachment)

GET: https://outlook.office365.com/api/v1.0/me/messages/{messageid}/attachments

RESPONSE:

{
  "@odata.context": "https://outlook.office365.com/api/v1.0/$metadata#Me/{messageid}/Attachments",
  "value": [
    {
      "@odata.type": "#Microsoft.OutlookServices.ItemAttachment",
      "@odata.id": "https://outlook.office365.com/api/v1.0/Users('{useremailaddress}')/{messageid}/Attachments('{messageid}')",
      "Id": "{messageid}",
      "Name": "{subject}",
      "ContentType": "message/rfc822",
      "Size": 54425,
      "IsInline": false,
      "DateTimeLastModified": "{timestamp}"
    }
  ]
}

Am I doing something wrong?

p4gs
  • 51
  • 1
  • 5

1 Answers1

4

Yes, our documentation needs to be much clearer on how to retrieve the Item. Please try https://outlook.office365.com/api/v1.0/me/messages/{messageid}/attachments/{AttachmentId}?$expand=Microsoft.OutlookServices.ItemAttachment/Item and let me know if this works for you.

Venkat Ayyadevara - MSFT
  • 2,850
  • 1
  • 14
  • 11
  • Awesome! I had to slightly modify the value of the "expand" parameter (it should be Microsoft.OutlookServices.ItemAttachment without the 's' at the end), but it works! – p4gs Sep 30 '15 at 17:47
  • 2
    Hey @Venkat Ayyadevara - MSFT - if an ItemAttachment has FileAttachments within it, how do I access those attachments? I've tried the following: `https://outlook.office365.com/api/v1.0/me/messages/{messageid}/attachments/{AttachmentId}?$expand=Microsoft.OutlookServices.ItemAttachments/Item/Attachments` And: `https://outlook.office365.com/api/v1.0/me/messages/{messageid}/attachments/{AttachmentId}?$expand=Microsoft.OutlookServices.ItemAttachments/Attachments` – p4gs Oct 14 '15 at 18:13
  • Sorry for the delay. I see you posted a question as well. Will get you the instructions. Thanks! – Venkat Ayyadevara - MSFT Oct 20 '15 at 16:30
  • Sorry, this isn't currently supported today. We will put this on our product backlog. – Venkat Ayyadevara - MSFT Oct 20 '15 at 20:25
  • 1
    It works to a point, I am getting Item populated, but not fully. The main part ID is missing -- without it, I cannot retrieve the item with it's attachments. Is there anything that is used as Item Id? I even tried to parse message web link, but it's wrong, id is too short. – Dmitriy Jun 02 '17 at 15:32
  • why api is different from this response? https://stackoverflow.com/a/48312551/1554241 – Rajeev Nov 20 '18 at 13:53