I need to read the O365 messages, find the right subject and body and print log message, using 0365 API.
Im connect to o365 api, get token and messages.
$connectionString = @{
'cliendid' = ""
'tenantid' = ""
'clientsecret' = "" convertto-securestring -asplaintext -froce
}
$token = Get-MsalToken @connectionString
$accestoken = $token.AccesToken
$mailuser = "[email protected]"
$graphapi = "https://graph.microsoft.com/v1.0/users/$mailuser/mailfolders/Inbox/messages"
$responce = Invoke-RestMethod -Method get -Uri $graphapi -ConectType "application/json" -Headers @{Autorization=("bearer {0}" -f $accestoken)}
And how do I read the response json and find needed subject now ? Thank you very much!
List messages - Microsoft Graph
The MS Graph API Documentation will show an example of a response to your API call.
A call like this should return an array of message objects in your "responce" variable. I believe if you express and look in $responce.Content[0] it will contain your first message. So, according to API Docs, $responce.Content[0].Subject should be your first subject. If you run...
You should get a grid view listing all properties of your response content. It's been a little while since I've used Graph API so the "drill down" to the content array may be a bit different. Each element of the content array should be in a format like below (From Graph API docs).