4

I'm trying to retrieve attachments in the Office365 rest api. Since I want to avoid downloading the entire attachments, I'm using a select clause to avoid downloading the content, which is in the ContentBytes property:

    $select="ContentId,ContentType,Id,IsInline,Name,Size"

So basically, I want to retrieve everything except the content. However, this gives the following error message (json):

    { 
       "error": 
          {
           "code": "RequestBroker-ParseUri",
           "message": "Could not find a property named 'ContentId' on type 'Microsoft.OutlookServices.Attachment'."
          }
    }

It's telling me that ContentId doesn't exist, which contradicts the specifications.

Edit: Here is the full request:

    GET /api/v2.0/me/messages/AAMkAGZlZjI3N2I3LTg1YWUtNDFiNC05MGI0LTVjYTVmZGI5NGI2YQBGAAAAAABzr8uDji9LRqgTCEsDv22wBwBWTXbvZW0dTKuxUGxpK4-lAAAAAAEMAABWTXbvZW0dTKuxUGxpK4-lAAC5QnKBAAA=/attachments?%24select=ContentId%2CContentType%2CId%2CIsInline%2CName%2CSize 

Even more strange, when I do the same query without specifying any select clause, it returns me a full attachment object, including a ContentId.

Anybody can help?

gwyers
  • 105
  • 5
  • `ContentId` is part of `Microsoft.OutlookServices.FileAttachment`. Check to make sure you are specifying the correct type. Without seeing your complete code we can not tell. – Brian from state farm Feb 03 '16 at 13:51
  • Brian, I see your point and it fits with the error message. However I don't see any REST call to look for FileAttachments instead of Attachments. Have I overlooked this? – gwyers Feb 03 '16 at 14:17
  • Using the REST API you may only be able to query the common base items in the Attachment object. – Brian from state farm Feb 03 '16 at 14:21

3 Answers3

9

In case anyone has the same question for microsoft graph, you need to pass this filter:

$select=microsoft.graph.fileAttachment/contentId

like this:

GET https://graph.microsoft.com/v1.0/me/messages/attachments?$select=microsoft.graph.fileAttachment/contentId
magicgregz
  • 7,471
  • 3
  • 35
  • 27
1

The request that you posted is getting the message specifications but not the attachments. Since you need to get the content id, you need to add /attachments to the request with any required parameters.

GET https://outlook.office.com/api/v2.0/me/messages/{message_id}/attachments/{attachment_id}

So please add the attachments to your query to be able to get the content id.

Hope this helps.

Mostafa
  • 3,296
  • 2
  • 26
  • 43
1

Solved it. The answer was suggested by Brian's comment and I found an additional hint here. Since 'ContentId' is a property of a FileAttachment, you need to specify that in the request, like so:

    $select="Microsoft.OutlookServices.FileAttachment/ContentId,ContentType,Id,IsInline,Name,Size"

That did the trick. Thanks for the suggestions.

Community
  • 1
  • 1
gwyers
  • 105
  • 5