How to know which mailFolder is the Inbox?
Asked Answered
A

2

5

Calling /users/me/mailFolders returns the folders list with their id, displayName, parentFolderId, and some counters.

How can I determine which folder is the "Inbox"?

I cannot use displayName because this will probably be in the user's native language. And the Id is just a random string.

I need this because my app populates the list of folders and I want to default the "selection" to the Inbox (just like Outlook does).

Artemas answered 12/2, 2018 at 12:56 Comment(0)
H
6

For the default folders, you can use a "well-known name" (in this case inbox) to get the correct id. From the documentation:

Outlook creates certain folders for users by default. Instead of using the corresponding folder id value, for convenience, you can use the following well-known folder names when accessing these folders in a mailFolder collection: ArchiveRoot, ConversationHistory, DeletedItems, Drafts, Inbox, JunkEmail, Outbox, and SentItems.

To illustrate, calling /me/mailFolders/inbox in the sample Graph Explorer tenant returns:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('48d31887-5fad-4d73-a9f5-3c356e68a038')/mailFolders/$entity",
    "id": "AAMkAGVmMDEzMTM4LTZmYWUtNDdkNC1hMDZiLTU1OGY5OTZhYmY4OAAuAAAAAAAiQ8W967B7TKBjgx9rVEURAQAiIsqMbYjsT5e-T7KzowPTAAAAAAEMAAA=",
    "displayName": "Inbox",
    "parentFolderId": "AAMkAGVmMDEzMTM4LTZmYWUtNDdkNC1hMDZiLTU1OGY5OTZhYmY4OAAuAAAAAAAiQ8W967B7TKBjgx9rVEURAQAiIsqMbYjsT5e-T7KzowPTAAAAAAEIAAA=",
    "childFolderCount": 2,
    "unreadItemCount": 59,
    "totalItemCount": 60
}
Hardware answered 13/2, 2018 at 20:40 Comment(1)
Good workaround! Just for note, response can be simplified for this purpose calling /me/mailFolders/inbox?$select=id.Artemas
P
4

In v1.0, I think you'll have to use the localized display names which as you mentioned, can be quite tricky. However, if you use the /beta/ endpoint, you can use the wellKnownName property which is a non-localized identifier for a given mailFolder (eg. 'junkemail', 'inbox', etc).

Phaedrus answered 12/2, 2018 at 17:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.