Getting Category E-mail from outlook with Power Automate + Microsoft Graph

1.- Register an application

Go to azure portal select App registrations , choose a name and click in register 


We are going to need this numbers later 

2.- Create a secrets

Go to Certificate and Secrets , click in + New client secret

Important: Copy the Value in a note ,it's going to be blocked and you are not able to see the entire number again

3.- Giving API permissions (Delegated permissions)

In API permissions option click in + Add permission , select Microsoft Graph and look for Mail.ReadBasic, Mail.Read according to documentation provided for Microsoft API Graph should be enough in my case I added  . See Documentation


4.- Creating the flow

In this case I used (When an email is flagged trigger)  , next step add an action HTTP , with this action we are going to get the token for our registered app on azure portal.

Configure the action as you see in the picture , replace the text in red with your values

URI     : https://login.microsoftonline.com/tenantid/oauth2/v2.0/token

Body  :    

grant_type=password&Username=username&Password=password&client_id=ApplicationID&            scope=https://graph.microsoft.com/.default&client_secret=secretid

Note   The grant_type in this case should be configure with the user credentials , remember we are working with delegated permissions , if you want to work with application permissions change the grant_type to client_credentials :

grant_type = client_credentials

Save and run the flow.

Even after gave the permissions on azure portal , I was reciving this error .

{"error":"invalid_grant","error_description":"AADSTS65001: The user or administrator has not consented to use the application with ID 'a95ea076-91eb' named 'MailCategory'. Send an interactive authorization request for this user and resource.\r\nTrace ID: 354e5087-44ee\r\nCorrelation ID: f863806b-07cc\r\nTimestamp: 2023-04-04 16:03:38Z","error_codes":[65001],"timestamp":"2023-04-04 16:03:38Z","trace_id":"354e5087","correlation_id":"f863806b-07cc-4bfa","suberror":"consent_required"}


4.1- Fixing the "AADSTS65001" error

I used a request in postman for fix this problem. First create a + New Collection


Create a new fork on your new collection, fill with the label fork and click on Fork Collection 

On the tab New Collection select Type OAuth 2.0

Go to Authorization and complete the configuration as you see , for the next part click on Edit token configuration

Next step , complete the information , change with your values the text in red and click on Get New Access Token

Token Name              : APPToken

Grant Type              : Authorization Code

Auth URL                : https://login.microsoftonline.com/TenanID/oauth2/v2.0/authorize

Access Token URL        : https://login.microsoftonline.com/TenanID/oauth2/v2.0/token

Client ID               : Client ID

Client Secret           : Client Secret

Scope                   : https://graph.microsoft.com/.default

State                   : 12345

Client Authentication   : Send as Basic Auth header

a windows pop-up will appear ,click on your account and give the permissions 

you will recive this message error , ignore it and now we are ready to try with the flow again

At this point you should be able to recive the token authorization , now we need to get the token value , copy the output body and paste in the next action for our flow using a Parse JSON , add compose with the output from previous action

now we are going to call the last action where we get the mail category , add an action HTTP and configure as you see in the picture , in the token Bearer put the output from your compose

Method  : Get

URI     : https://graph.microsoft.com/v1.0/me/messages/{ID}

Headers : Authorization  Bearer Token

  Content-Type   application/json


save your flow and run

as you see now we get the category  you can add other actions for manipulate the categogy add Parse Json and compose actions

save and run the flow

I hope this little article help you and gives you an approch for how to send a request trough power automate and microsoft graph.