Reputation: 301
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).
Upvotes: 6
Views: 6636
Reputation: 33132
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
, andSentItems
.
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
}
Upvotes: 6
Reputation: 739
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).
Upvotes: 4