fetching attached itemAttachements of office365 emails using Graph API

Supriya A 1 Reputation point


I need to download attachments from selected Office365 email recursively.

I tried below request from one of the solution provided online,

RequestUri = {https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/{msgID}/attachments/{attachedmsgID}=/?$expand = microsoft.graph.itemattachment/item}

but getting below response.

StatusCode: 404, ReasonPhrase: 'Not Found'

can anyone please let me know how do I fetch itemAttachments and its attachments?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
23,912 questions
No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Mohammed Mehtab Siddique (MINDTREE LIMITED) 731 Reputation points Microsoft Employee

    Hi @Supriya A ,

    For getting the itemAttachements of mail please follow the below instructions:

    Expand and get the properties of the item attached to a message:

    GET https://graph.microsoft.com/v1.0/me/messages/AAMkADA1M-zAAA=/attachments/AAMkADA1M-CJKtzmnlcqVgqI=/?$expand=microsoft.graph.itemattachment/item  

    Expand and get the properties of an item attached to a message, including any attachment to the item:

    GET https://graph.microsoft.com/v1.0/me/messages/AAMkADA1M-zAAA=/attachments/AAMkADA1M-CJKtzmnlcqVgqI=/?$expand=microsoft.graph.itemattachment/item  

    For fetching these details you need to have the following permission:


    You can also decode your Token in the https://jwt.ms/ and check in scope whether these permissions are already available.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

  2. AtulThorat-MSFT 386 Reputation points

    Hi @Supriya A ,

    Hope you are doing well.

    As per documentation,attachment-get and query-parameters we can get attachment of mail message and can use query parameters to customize responses.

    $expand query parameter can be used as shown below. I have tried this in graph explorer and I could able to get correct response as shown below.

    GET https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/{messageID}/attachments/{attachmentID}$expand=microsoft.graph.itemattachment/item



    So we are unable to reproduce this issue.

    You are getting StatusCode: 404, ReasonPhrase: 'Not Found' so Please try to use graph api endpoint attachment-get and check weather this attachment file is still available for particular mail message or not.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

  3. Supriya A 1 Reputation point

    Hi, I was not able to comment so writing an answer,
    @AtulThorat-MSFT , I tried with below endpoint,

    RequestUri = {https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/{msg-id}/attachments/{attachment-id}/?$Value}

    and getting below response,

    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('supriyatest2021%40outlook.com')/mailFolders('Inbox')/messages('AQMkADAwATM3ZmYAZS00NjJhLWFiYgA2LTAwAi0wMAoARgAAA4Amv2sM8nJEo5QlvuMbUbMHAOyxeWKJD4JHrqegw15KyEAAAAIBDAAAAOyxeWKJD4JHrqegw15KyEAAAACEBqjhAAAA')/attachments/$entity",
    "@odata.type": "#microsoft.graph.itemAttachment",
    "lastModifiedDateTime": "2022-06-15T05:16:48Z",
    "name": "test 1",
    "contentType": "message/rfc822",
    "size": 8575119,
    "isInline": false

    means the itemAttachment is present, then not sure why I am not able to get the item itself, when I try below?

    {https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/{msgID}/attachments/{attachedmsgID}=/?$expand = microsoft.graph.itemattachment/item}

    Also this itemAttachment has another fileAttachment, but I do not get ContentID in above response( with $Value)?