0
votes

I want to be able to get the number of unread emails for an specific name in my tenant.

Something like: https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages?$filter=isRead ne false&$count=true]

but be able to change the me for an specific user, the above works in graph explorer for my signing user.

I tried this example here. Which bring me a list of users and was trying to modified it without success.

the app have api permission for microsoft graph to read mail in all mailboxes.

3

3 Answers

1
votes

To access a users mailbox other than the signed in user. You will need to call the api with an application (app-only) token. This will require requesting application permissions (not delegate permissions) for Mail.Read.

More information on getting access without a user context is available here https://docs.microsoft.com/en-us/graph/auth-v2-service?context=graph%2Fapi%2F1.0&view=graph-rest-1.0

The request would be GET https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/messages

You can use the id from calling GET https://graph.microsoft.com/v1.0/users

or use the upn which is their email address in most cases that you may already have.

More documentation is available here https://docs.microsoft.com/en-us/graph/api/user-list-messages?view=graph-rest-1.0&tabs=http

You can actually test these request calls in our Postman collections. Graph Explorer is purely for on-behalf of flow request calls. Setup instructions are here https://docs.microsoft.com/en-us/graph/use-postman

0
votes

I may be misunderstanding your question, but I think your trouble is you're replacing me in the URI with the user identifier. If that's correct, you need to replace it with user/useridentifier instead.

That would make the query:

https://graph.microsoft.com/v1.0/user//mailFolders/Inbox/messages?$filter=isRead ne false&$count=true

0
votes

Just pass UserID in GET API

{{UserId}} - username/mailid/principalName
    
 https://graph.microsoft.com/v1.0/users/{{UserId}}/mailFolders/Inbox/messages?$filter=isRead ne true&$count=true