Thank you for the rapid response.
My understanding of the personal messages is that '/me/messages' is using the signed in user auth option and i am trying to make a application with a token auth.
Therefor the '/me/messages' is resulting in a 403 no auth error. Which is understandable.
Here is the PS code i am using. (Client id , tenant and secret vars removed).
$clientID = ""
$tenantdomain = ""
$clientSecret = ""
$loginURL = "https://login.microsoft.com"
$resource = "https://graph.microsoft.com"
$body = @{grant_type="client_credentials";resource=$resource;client_id=$ClientID;client_secret=$ClientSecret}
$oauth = Invoke-RestMethod -Method Post -Uri $loginURL/$tenantdomain/oauth2/token?api-version=1.0 -Body $body
$headerParams = @{'Authorization'="$($oauth.token_type) $($oauth.access_token)"}
#_____________________________________________________________________________________________
$url = 'https://graph.microsoft.com/v1.0/users/'
## This lists my user information
$userList = Invoke-WebRequest -Method Get -UseBasicParsing -Headers $headerParams -Uri $url | ConvertFrom-Json
ForEach ($user In $userList.Value) {
$user
}
## i add this to test the messages.
userList = Invoke-WebRequest -Method Get -UseBasicParsing -Headers $headerParams -Uri $url | ConvertFrom-Json
The code above gives me my user information and ID.
When i alter the URL to 'https://graph.microsoft.com/v1.0/users/MYUSERID/messages' i get the 404.
When i try the same url method using the https://developer.microsoft.com/en-us/graph/graph-explorer my messages are listed.