Can I fetch only spam mails via Microsoft Graph Api?

800 Views Asked by At

I am trying to fetch Spam mail present in my mailbox via Microsoft Graph API. But I can't find any related documents on how to achieve that.

From this link https://learn.microsoft.com/en-us/graph/api/user-list-messages, I am able to retrieve all messages present in my inbox. But is there any way to fetch only particular folder messages like Spam, Trash etc...

Does anyone have any idea on how to achieve the above scenario? If yes, can someone help me out.

1

There are 1 best solutions below

0
user2250152 On

As mentioned in the doc to get messages in a specific folder in the user's mailbox you can call these endpoints:

GET /me/mailFolders/{id}/messages
GET /users/{id | userPrincipalName}/mailFolders/{id}/messages

Instead of mail folder id you can use well-known folder name

GET /me/mailFolders/junkemail/messages
GET /me/mailFolders/deleteditems/messages