user-list-mailfolders does not return mail search folders?

Wang, Wei 41 Reputation points

The Graph API user-list-mailfolders function is supposed to return "the mail folder collection directly under the root folder of the signed-in user", including any mail search folders directly under the root."

I am writing a tool to monitor an email inbox and search for specific messages. Using the "mail search folder" feature, I want to use that set of APIs to create a folder with search criteria, so I can simply iterate through that folder for messages I need to process.

The problem is that, after the search folder is created, the user-list-mailfolders API function does not return the mail search folder. My code would try to create the folder again and gets an error thrown at it:

{"code":"ErrorFolderExists","message":"A folder with the specified name already exists., Could not create folder 'CronSearch'."}

My question is why the search folder is not returned by the user-list-mailfolders API function as the documentation clear says it does.

Thanks for any thoughte and insights.


Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,798 questions
0 comments No comments
{count} votes

Accepted answer
  1. Shivam Dhiman 5,946 Reputation points

    Hi @Wang, Wei

    As per my testing, to get the mail search folders, you can use beta to get mail search folders.

    Please note: APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.

    Also, you can use List childFolder in v1.0 but in this case, you need to iterate through mailFolders where you have created search folder.
    GET /me/mailFolders/{id}/childFolders

    GET /users/{id | userPrincipalName}/mailFolders/{id}/childFolders

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    0 comments No comments

0 additional answers

Sort by: Most helpful