简体   繁体   中英

trying to get unread message count with Microsoft graph on multiple emails

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM