A couple weeks ago, I posted an article about an Intro to the Microsoft Graph .NET Client Library. That article was really focused on setting up the environment and making some initial calls to retrieve some data. This article is focused on some additional operations, as well as some more advanced capabilities of the Microsoft Graph .NET Client Library.
I think for this post, instead of writing a bunch of verbiage, I’ll just describe some basic scenarios and then show the code that might be an option to solve the problem. Everyone likes seeing code the best anyway, right?
Scenario: We’ve written some code that gathers up thousands of users in our organization. However, the call is pretty slow. All we really need is the first name, last name, city, and state of the user. Can we reduce the amount of data being returned during the call to help mitigate some of the network payload?
Absolutely we can, using the Select function from the Request function, much like SELECT in SQL. As you can see, all of the fields are null except for the fields that we requested be returned.
Scenario: We’d like to retrieve the e-mail messages in a mailbox so that they can be displayed in some kind of external client. Maybe something like The Help Desk Demo.
Sure, we’ll just find the mailbox, retrieve the messages, and then sort by the receivedDateTime desc so that the newest messages are at the front of the list.
Scenario: So far, we’ve just talked about retrieving data. What if we want to create a new group? Sure, no problem. Note, at this time, you cannot create mail enabled groups via the Microsoft Graph. Total bummer.
I suppose once we’ve create a group, it might make sense to also create a user as well. Easy enough:
Now, what if we want to add that user to the group that we created previously? At first glance, it would seem that maybe we’d want to do something like newGroup.Members.Add(user). It turns out that what we really want to do is to create a reference between the user and group instead, like so:
And sure enough, we find that Frank Jones is now a member of the Finance Department group:
What about deleting that member? Sure, we’ll just delete the reference, like so:
And we can see that Frank Jones was, in fact, removed from the Finance Department group:
What else? What else would be helpful to see demonstrated? Leave a comment and I’ll try and make it happen!