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

Wang, Wei 41 Reputation points
2023-03-15T00:59:00.31+00:00

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.

--Wei

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
865 questions
Microsoft Graph Users API
Microsoft Graph Users API
A Microsoft API that allows you to build compelling app experiences based on users, their relationships with other users and groups, and the resources they access for example their mails, calendars, files, administrative roles, group memberships.
641 questions
No comments
{count} votes

Accepted answer
  1. Shivam Dhiman-MSFT 5,186 Reputation points Microsoft Vendor
    2023-03-15T03:49:48.24+00:00

    Hi @Wang, Wei

    As per my testing, to get the mail search folders, you can use beta to get mail search folders.
    GET https://graph.microsoft.com/beta/me/mailFolders

    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 additional answers

Sort by: Most helpful