Share via

How to retrieve all uncategorized emails in office 365 mailbox using Microsoft graph api in PowerShell

Benard Mwanza 1,006 Reputation points
2022-05-27T20:00:17.84+00:00

Is it possible to retrieve all uncategorized emails in office 365 mailboxes using Microsoft graph API. If yes, how does the microsoft graph api endpoint look like.

Have tried below but its not working

$mail_user = "emailaccounthere"
$graphuri = "https://graph.microsoft.com/v1.0/users/$mail_user/mailfolders/Inbox/messages?$filter=categories/any(a:a+eq+'Null+Category')&count=true"


$resp = Invoke-RestMethod -Method get -Uri $graphuri -ContentType "application/json" -Headers @{Authorization=("bearer {0}" -f $accessToken)}

$resp | fl
Exchange Online
Exchange Online

A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.

Microsoft Security | Microsoft Graph

8 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

  5. Benard Mwanza 1,006 Reputation points
    2022-05-30T09:44:28.727+00:00

    Hello @Zehui Yao_MSFT Thank you for the concern. Below is the solutions.

    GET https://graph.microsoft.com/v1.0/users/$mail_user/mailfolders/Inbox/messages?  
        $select=categories&$filter=NOT(categories/any())&count=true  
    

    If $filter=categories/any() would return all messages with any category, then the opposite of that can be achieved by using not operator. That successfully returned all messages without any category applied.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.