Ashwin Kumar
Ashwin Kumar

Reputation: 11

Microsoft graph api- Filtering on attached file extensions

I am using ms graph api to get all the messages with attachments. Over this I need to get the files having docx/pdf extensions. Below are the filters I have tried.

https://graph.microsoft.com/v1.0/me/messages?$filter=hasAttachments eq true and ext eq 'docx'

https://graph.microsoft.com/v1.0/me/messages?$filter=hasAttachments eq true and extensions eq 'docx'

Upvotes: 1

Views: 3585

Answers (1)

Marc LaFleur
Marc LaFleur

Reputation: 33094

You'll need to do this using multiple API calls. First you need to retrieve a list of messages with attachments (has Attachments) and then you need to iterate over the resulting ids in order to retrieve the attachment metadata.

For example, the call returns a list of message ids that have attachments:

https://graph.microsoft.com/v1.0/me/messages?$filter=hasAttachments eq true&$select=id

For each of the IDs we got back, we then make a second call to get the attachments:

https://graph.microsoft.com/v1.0/me/messages/{message id}/attachments

From these results you can inspect the Attachment's name property to determine what the file extension is.

Upvotes: 5

Related Questions