How to retrieve ItemAttachment contents from Offic

2020-01-27 06:45发布

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?

1条回答
三岁会撩人
2楼-- · 2020-01-27 07:36

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.

查看更多
登录 后发表回答