Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

How to retrieve ItemAttachment contents from Office 365 REST API?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...