2

We're using MS Graph API to get the list of emails from an Outlook 365 mailbox. We have a requirement to list the attachments in every email.

When using the List Attachments endpoint of the Graph API, the contentBytes attribute value in the response contains the entire Base64 encoded attachment content. This increases the response size significantly. We have no need to access or store the attachment content.

https://learn.microsoft.com/en-us/graph/api/message-list-attachments?view=graph-rest-1.0&tabs=http#example

Is there a way in MS Graph API to just get the attachment file name(s) and IDs for one or more email messages?

Aditya Kar
  • 515
  • 5
  • 12

1 Answers1

3

Yes, you can use the same /attachments endpoint and get only the id and name of attachment using the $select query parameter.

Simply use the query

https://graph.microsoft.com/v1.0/me/messages/{messageid}/attachments?$select=id,name

Result:

enter image description here

You can always test graph calls in Graph Explore.

Shiva Keshav Varma
  • 3,398
  • 2
  • 9
  • 13
  • 1
    Thank you, Shiva! This works like a charm! I'm using the Python [O365](https://github.com/O365/python-o365/blob/master/O365/utils/attachment.py) library. Unfortunately, it doesn't provide a way to specify the select parameters out-of-the-box. I'll extend the BaseAttachment class to do that. – Aditya Kar Apr 14 '21 at 14:39
  • Glad to here that it helped you :)- – Shiva Keshav Varma Apr 14 '21 at 15:43