In my application that uses the Outlook REST API, in order to support inlined images in html emails, I need to retrieve the ContentId
of the File Attachments of a given email.
Note: in an html email inlined images are html tags of the form <input scr="cid:mycontentid">
I manage to get this information at url https://outlook.office.com/api/v2.0/me/messages/{message_id}/attachments
The problem is the returned json also contains the ContentBytes
which can be arbitrary big for large attachments.
I tried several syntaxes to retrieve only the fields that I need such as:
https://outlook.office.com/api/v2.0/me/messages/{message_id}/attachments?$select=Id,ContentId
or '$select=Id&$expand=ContentId'
none of them worked, resulting in a bad request
{"error":{"code":"RequestBroker-ParseUri","message":"Could not find a property named 'ContentId' on type 'Microsoft.OutlookServices.Attachment'."}}
The expected types at url '/attachments'
are Microsoft.OutlookServices.Attachment
which is a base type for File Attachments and Item Attachment.
I would like to retrieve the specific member for File Attachments (ContentId
) or to discard the heavy ContentBytes
contained in the result.
The endpoint of me/messages/{message_id}/attachments
return the collection of attachment.
The ContentId is the property of FileAttachment. You can use the code below to get the contentId of fileAttachment:
GET: https://outlook.office.com/api/v2.0/me/messages/{messageId}/attachments?$select=Microsoft.OutlookServices.FileAttachment/ContentId
EDIT:
Remark: if you want to retrieve other field, say Name
note that $select=Microsoft.OutlookServices.FileAttachment/ContentId,Name
will work while that $select=Name,Microsoft.OutlookServices.FileAttachment/ContentId
will throw the error mentioned in the original question