Search code examples
c#microsoft-graph-api

Filtering GraphAPI Query to retrieve only the Inbox Mailfolder


I'm trying to filter my GraphAPI query to return only MailFolders that have the displayName "Inbox." From what I can tell, this should be fairly easy with: requestConfiguration.QueryParameters.Filter But I think my filter command is incorrect, and I'm struggling to find documentation on the proper way to write this.

I've tried following the steps here, but I don't understand what i:i or s:s do, and any time I run the command below, no results are returned:

https://learn.microsoft.com/en-us/graph/filter-query-parameter?tabs=csharp

Any help would be appreciated!

I tried:

return _appClient.Users[userID].MailFolders.GetAsync((requestConfiguration) => {
            requestConfiguration.QueryParameters.Filter = "displayName/any(i:i eq 'Inbox')";
        });

and expected it to return only the inbox folder for the given user, but instead it returns nothing.


Solution

  • displayName is not a collection, so no need to use any operator

    return _appClient.Users[userID].
           MailFolders
           .GetAsync((requestConfiguration) => {
                requestConfiguration.QueryParameters.Filter = "displayName eq 'Inbox'";
            });
    

    But I would prefer to use well-known folder names

    return _appClient.Users[userID].MailFolders["Inbox"].GetAsync()