Alexis Nguyen
Alexis Nguyen

Reputation: 35

How to grab a user's mailbox setting using the Graph SDK

I'm having trouble trying to obtain this data using the Graph client library found here: https://www.nuget.org/packages/Microsoft.Graph in my c# application. I'm aware that the data is available using this REST API call.

I've created my azure application and provided the application "Read all user mailbox settings" permissions and clicked on "grant permissions" to apply them. The problem is not with my authentication. I'm able to retrieve data.

MicrosoftAuthenticationProvider authProvider = 
    new MicrosoftAuthenticationProvider(applicationID, applicationSecret, microsoftURL);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
IGraphServiceUsersCollectionPage users = await graphClient.Users.Request().GetAsync();
foreach (User user in users)
{
    //user.MailboxSettings
    //returns null, but through intellisense, I can obtain it's attributes
    //Microsoft.Graph.MailboxSettings is available in the library's object browser

    //graphClient.Users[user.UserPrincipalName].MailboxSettings.Request().GetAsync() 
    //User.MailboxSettings is not available
}

As a last resort, I'll use the REST API, but if I can, I want to just use the library.

Upvotes: 2

Views: 2195

Answers (1)

Seiya Su
Seiya Su

Reputation: 1874

Just append Select("MailboxSettings") to your query.

Get users's MailboxSetting based on your code

                IGraphServiceUsersCollectionPage users = await 
                    graphClient.Users.Request().GetAsync();

                foreach (User user in users)
                {
                    User fullUser = await graphClient.Users[user.UserPrincipalName].Request().Select("MailboxSettings").GetAsync();

                    MailboxSettings mailboxSettings1 = fullUser.MailboxSettings;                     
                }

enter image description here

Upvotes: 5

Related Questions